THE BINARY SYSTEM.

Slides:



Advertisements
Similar presentations
ICS312 Set 2 Representation of Numbers and Characters.
Advertisements

Representing Numbers: Integers
HEXADECIMAL NUMBERS Code
Chapter 2 : Number System
Digital Fundamentals Floyd Chapter 2 Tenth Edition
Assembly Language and Computer Architecture Using C++ and Java
Assembly Language and Computer Architecture Using C++ and Java
Number Systems Decimal (Base 10) Binary (Base 2) Hexadecimal (Base 16)
VIT UNIVERSITY1 ECE 103 DIGITAL LOGIC DESIGN CHAPTER I NUMBER SYSTEMS AND CODES Reference: M. Morris Mano & Michael D. Ciletti, "Digital Design", Fourth.
Data Representation in Computers
Digital Fundamentals Floyd Chapter 2 Tenth Edition
DIGITAL SYSTEMS TCE1111 Representation and Arithmetic Operations with Signed Numbers Week 6 and 7 (Lecture 1 of 2)
S. Barua – CPSC 240 CHAPTER 2 BITS, DATA TYPES, & OPERATIONS Topics to be covered are Number systems.
Signed Numbers CS208. Signed Numbers Until now we've been concentrating on unsigned numbers. In real life we also need to be able represent signed numbers.
COMP201 Computer Systems Number Representation. Number Representation Introduction Number Systems Integer Representations Examples  Englander Chapter.
Digital Logic Chapter 2 Number Conversions Digital Systems by Tocci.
Dr. Bernard Chen Ph.D. University of Central Arkansas
© 2009 Pearson Education, Upper Saddle River, NJ All Rights ReservedFloyd, Digital Fundamentals, 10 th ed Digital Fundamentals Tenth Edition Floyd.
ACOE1611 Data Representation and Numbering Systems Dr. Costas Kyriacou and Dr. Konstantinos Tatas.
Data Representation – Binary Numbers
CSCI-365 Computer Organization Lecture Note: Some slides and/or pictures in the following are adapted from: Computer Organization and Design, Patterson.
1 Digital Technology and Computer Fundamentals Chapter 1 Data Representation and Numbering Systems.
1 Digital Systems and Binary Numbers EE 208 – Logic Design Chapter 1 Sohaib Majzoub.
ECEN2102 Digital Logic Design Lecture 1 Numbers Systems Abdullah Said Alkalbani University of Buraimi.
Number Systems Spring Semester 2013Programming and Data Structure1.
Digital Logic Design Lecture 3 Complements, Number Codes and Registers.
Information Representation. Digital Hardware Systems Digital Systems Digital vs. Analog Waveforms Analog: values vary over a broad range continuously.
Logic Design Dr. Yosry A. Azzam. Binary systems Chapter 1.
10-Sep Fall 2001: copyright ©T. Pearce, D. Hutchinson, L. Marshall Sept Representing Information in Computers:  numbers: counting numbers,
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Representation of Data Ma King Man. Reference Text Book: Volume 2 Notes: Chapter 19.
Engineering 1040: Mechanisms & Electric Circuits Spring 2014 Number Systems.
ECE 301 – Digital Electronics Unsigned and Signed Numbers, Binary Arithmetic of Signed Numbers, and Binary Codes (Lecture #2)
Cosc 2150: Computer Organization Chapter 2 Part 1 Integers addition and subtraction.
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
1 Representation of Data within the Computer Oct., 1999(Revised 2001 Oct)
Computer Math CPS120: Lecture 3. Binary computers have storage units called binary digits or bits: Low Voltage = 0 High Voltage = 1 all bits have 0 or.
Data Representation, Number Systems and Base Conversions
ECE 331 – Digital System Design Representation and Binary Arithmetic of Negative Numbers and Binary Codes (Lecture #10) The slides included herein were.
Computer Math CPS120 Introduction to Computer Science Lecture 4.
AEEE2031 Data Representation and Numbering Systems.
SAK Chapter 21 Chapter 2 : Number System 2.1 Decimal, Binary, Octal and Hexadecimal Numbers 2.2 Relation between binary number system with other.
WEEK #2 NUMBER SYSTEMS, OPERATION & CODES (PART 1)
Number Systems by Dr. Amin Danial Asham. References  Programmable Controllers- Theory and Implementation, 2nd Edition, L.A. Bryan and E.A. Bryan.
Digital Fundamentals Tenth Edition Floyd Chapter 2 © 2008 Pearson Education.
Chapter 1: Binary Systems
1 Digital Logic Design Lecture 2 More Number Systems/Complements.
Introduction to Digital Electronics Lecture 2: Number Systems.
©2010 Cengage Learning SLIDES FOR CHAPTER 1 INTRODUCTION NUMBER SYSTEMS AND CONVERSION Click the mouse to move to the next page. Use the ESC key to exit.
Computer Organization 1 Data Representation Negative Integers.
Lecture No. 4 Computer Logic Design. Negative Number Representation 3 Options –Sign-magnitude –One’s Complement –Two’s Complement  used in computers.
Computer Math CPS120 Introduction to Computer Science Lecture 7.
CHAPTER 3 BINARY NUMBER SYSTEM. Computers are electronic machines which operate using binary logic. These devices use two different values to represent.
Number Systems. The position of each digit in a weighted number system is assigned a weight based on the base or radix of the system. The radix of decimal.
Binary Addition The simplest arithmetic operation in binary is addition. Adding two single-digit binary numbers is relatively simple, using a form of carrying:
Number Systems Decimal (Base 10) –10 digits (0,1,2,3,4,5,6,7,8,9) Binary (Base 2) –2 digits (0,1) Digits are often called bits (binary digits) Hexadecimal.
Lecture 4: Digital Systems & Binary Numbers (4)
Representing Positive and Negative Numbers
NUMBER SYSTEMS.
CHAPTER 1 : INTRODUCTION
Binary Arithmetic Binary arithmetic is essential in all digital computers and in many other types of digital systems. Addition, Subtraction, Multiplication,
Chapter 3 Data Representation
Number Systems.
University of Gujrat Department of Computer Science
Numbering System TODAY AND TOMORROW 11th Edition
Digital Logic & Design Lecture 02.
Digital Logic Design (ECEg3141) 2. Number systems, operations & codes 1.
Binary to Decimal Conversion
ECE 331 – Digital System Design
Presentation transcript:

THE BINARY SYSTEM

HOW A COMPUTER STORES DATA A computer is an information-processing machine that works by converting all kinds of information into binary numbers (1s and 0s). A computer treats any type of information (numbers, letters, words, etc.) as if it consisted simply of binary ones and zeros. For example, a computer can translate the letter “A” typed into its keyboard into a string of 1s and 0s, such as 1000001.   One reason to do this is that once in binary form; the information can be stored and moved about more easily. For example, on a hard disc, the 1s could be stored as magnetized spots on the disc, while the 0s can be stored as unmagnetized spots. Once information has been converted to 1s and 0s, the computer can work on it.    All of a computer’s functions are based on the movement and transformation of electrical pulses (representing 1s and 0s) in electrical circuits. Inside the computer are electrical circuits that perform computations on the 0s and 1s, such as adding and subtracting them.

The Decimal/Denary Number System (Base 10) The decimal number system that people use every day contains ten digits, 0 through 9. Start counting in decimal: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, Units/Ones 1 2 3 4 5 6 7 8 9 Oops! There are no more digits left. How do we continue counting with only ten digits?

The Decimal/Denary Number System We add a second column of digits, worth ten times the value of the first column. Start counting again: 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20 Tens Ones 1 2 1 3 1 4 1 5 1 6 1 7 1 8 1 9 2 0 (Note that the right column goes back to zero here.), 21, 22, 23, ... , 94, 95, 96, 97, 98, 99,

The Decimal/Denary Number System Oops! Once again, there are no more digits left. The only way to continue counting is to add yet another column worth ten times as much as the one before. Continue counting: 100, 101, 102, ...997, 998, 999, 1000, 1001, 1002, .... H T O Th H T O 1 0 0 1 0 0 0 1 0 1 1 0 0 1 . . 9 9 9 9 9 9 9 You should get the picture at this point!

The Decimal/Denary Number System Example, the decimal number 365 can be written in expanded notation as: H T O 102 101 100 (3×100) + (6×10) + (5×1) Th H T O 1032= (1×1000) + (0×100) + (3×10) + (2×1). By writing numbers in this form, the value of each column becomes clear.

The Binary System/Base 2 The binary number system works in the exact same way as the decimal system, except that it contains only two digits, 0 and 1. Start counting in binary: 0, 1, Oops! There are no more binary digits. In order to keep counting, we need to add a second column worth twice the value of the column before. We continue counting again: 10, 11, Oops! It is time to add another column again. Counting further: 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100, 1101, 1110, 1111.... Watch the pattern of 1's and 0's. You will see that binary works the same way decimal does, but with fewer digits.

The Binary System/Base 2 Binary uses two digits, so each column is worth twice the one before. 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1 N.B. Any number to the power 0 is 1 A A1 A = 1 & A1 = A (1-1) = A 0 = 1

Decimal (Base 10) Binary (Base 2) 0 one 1 1 one 2 10 0 one, 1 two 3 11 1 one, 1 two 4 100 0 one, 0 two, 1 four 5 101 1 one, 0 two, 1 four 6 110 0 one, 1 two, 1 four 7 111 1 one, 1 two, 1 four 8 1000 0 one, 0 two, 0 four, 1 eight

Conversion of a binary number to a decimal number To convert a number from binary to decimal, simply write it in expanded notation. For example, the binary number 101101 can be rewritten in expanded notation as 27 26 25 24 23 22 21 20 128 64 32 16 8 4 2 1 1 0 1 1 0 1 (1×32) + (0×16) + (1×8) + (1×4) + (0×2) + (1×1)= 32+0+8+4+0+1= 45 By simplifying this expression, you can see that the binary number 101101 is equal to the decimal number 45.

Converting from decimal to binary We use the method of repeated division by 2 to convert numbers from decimal to binary. Usually, when dividing a number by 2 the last binary digit (singles digit) must be a 1- the LSB. An even number will have a zero as the singles digit- the MSB. So to convert a Base 10 number to Base 2 the number is repeatedly divided by 2 until we have reached the point of 0 R 1. The remainders give us the binary digits.

Example: Convert decimal 25 to binary:- 25 ÷ 2 = 12 Remainder 1 12 ÷ 2 = 6 Remainder 0 6 ÷ 2 = 3 Remainder 0 3 ÷ 2 = 1 Remainder 1 1 ÷ 2 = 0 Remainder 1 1 1 0 0 1 The number 25 in decimal is equal to 110012 MSB LSB

QUESTIONS: Convert the following decimal numbers to binary. Use 8 bits to represent the numbers in base 2 16 182 97

BINARY ARITHMETIC OPERATIONS Binary numbers can be added, subtracted, multiplied or divided just like decimal numbers. ADDITION RULES!! 0 + 0 = 0 0 + 1 = 1 1 + 0 = 1 1 + 1 = 1 0 1 + 1 + 1 = 1 1 Carry bits

BINARY ADDITION To view binary addition: http://www.youtube.com/watch?v=Cqs90dhw_E4

Note, the fourth rule in Binary Addition involves a ‘carry’ operation: 21 20 1 + 1 = 1 0 The place value is increased by 2! This is similar to decimal where the place value is increased by ten. For example: 101 100 9 + 1 = 1 0

Base 2 Addition questions 111 111 111 101 + 110 + 111 + ______ _____ _____

HOME-WORK Read pages 57-58: Log On to It for CSEC (2nd Ed.):- Converting a decimal number to binary Adding binary numbers Do Exercise 1 Quest. 3, 4, 5 (Pg 59) Test Next Day!!!!!!!

REPRESENTATION SCHEMES In computing, signed number representations are required to encode negative numbers in binary number systems. In maths, negative numbers in any base are represented by prefixing them with a − sign. However, in computer hardware, numbers are represented in binary only without extra symbols, requiring a method of encoding the sign of the number.

REPRESENTATION SCHEMES Four methods that are used to represent signed numbers are: Sign-and-Magnitude One’s complement Two’s Complement Binary Coded Decimal (BCD)

SIGN AND MAGNITUDE The simplest way to indicate negation is signed magnitude .One may first approach the problem of representing a number's sign by allocating one sign bit to represent the sign: set that bit (often the most significant bit) to 0 for a positive number, and set to 1 for a negative number. The remaining bits in the number indicate the magnitude. Some early binary computers (e.g. IBM 7090) used this representation

SIGN AND MAGNITUDE Consider a number with n bits: The left-most bit represents the sign of the number +/- sign. "0" indicates that the number is positive, "1" indicates negative. The remaining n-1 bits represent the magnitude (size) of the number.

Representation of positive and negative numbers using Sign & Magnitude BINARY DECIMAL 0000 +0 0001 +1 0010 +2 0011 +3 0100 +4 0101 +5 0110 +6 0111 +7 1000 -0 1001 -1 1010 -2 1011 -3 1100 -4 1101 -5 1110 -6 1111 -7 What observations have you made from the table?

If you observed that there are two values for zero: +0 and -0 then you are RIGHT!

Example 1: Represent 45 in binary using Sign and Magnitude: 4510 = 001011012 Therefore +45 (S & M) = 00101101 0 (MSB) = +ve in Sign and Magnitude

Example 2: Represent -45 in binary using Sign and Magnitude: 4510 = 001011012 Therefore -45 (S & M) = 10101101 1 (MSB) = -ve in Sign and Magnitude

Example 3: Represent 1011 in decimal using Sign and Magnitude. 1 = -ve in Sign & Magnitude 011=(1x2) + (1x1) = 3 Therefore 1011 = -3 (using Sign & Magnitude) 22 21 20 4 2 1

Example 4: Represent 0011 in decimal using Sign and Magnitude. 0 = +ve in Sign & Magnitude 011=(1x2) + (1x1) = 3 Therefore 0011 = +3 (using Sign & Magnitude) 22 21 20 1

Questions 1. using Sign & Magnitude Representation, find the binary representation of the numbers: (a) 25 (b) -25 (c) 63 (d) -120 2. What is the decimal equivalent of the following binary numbers (using S & M scheme)? (a) 1000101 (b) 01000101 (c)11000101

HOME-WORK 1. Using Sign & Magnitude Representation, find the binary representation of the numbers: (a) 64 (b) -96 (c) 96 (d) -156 2. What is the decimal equivalent of the following binary numbers (using S & M scheme)? (a) 0010101 (b) 01100101 (c)10000001 * Read Page 55 (blue book) or pg 60 (purple book)- One’s & Two’s Complement

One’s Complement In one's complement, positive numbers are represented as usual in regular binary. Example: 5 in binary is 00000101. The One’s complement of 5 would be: 00000101 However, negative numbers are represented differently. To negate a number, replace all zeros with ones, and ones with zeros - flip the bits. One consequence of this is that there are two values for zero: +0 and -0.

For example, for a four-bit number (remember, the leading -- that is, leftmost -- bit is a sign bit) using 1’s Complement: Binary: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Decimal:  +0 +1 +2 +3 +4 +5 +6 +7 -7 -6 -5 -4 -3 -2 -1 -0

Questions Represent the following numbers in binary (using 8 bits) using 1’s complement: -108 23 4 -120

HOME-WORK 1. Represent the following decimal numbers using 1’s complement: -95 -36 100 2. Find the One’s Complement of: 1011001 0001010

TWO’S COMPLEMENT Two's complement is the way every computer chooses to represent integers. Using two's complement as the method for representing negative numbers allows us to have only one representation of zero, and to have effective addition and subtraction while still having the most significant bit as the sign bit. The leading bit of a number is the sign bit.  Positive numbers have a zero as the leading bit; negative numbers have a one as the leading bit. There is only one value for zero: all bits are zero (as opposed to the system used for One's Complement Overflow can occur (if numbers are of the same sign)

For example, for a four-bit number (remember, the leading -- that is, leftmost -- bit is a sign bit) USING 2’S COMPLEMENT Binary: 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Decimal:  +1 +2 +3 +4 +5 +6 +7 -8 -7 -6 -5 -4 -3 -2 -1

TWO’S COMPLEMENT In two's complement, positive numbers are represented as usual in regular binary. Example: 5 in binary is 00000101. The Two’s complement of 5 would be: 00000101 NO CHANGE!!

FINDING TWO’S COMPLEMENT (-VE NUMBERS) Convert the number to binary Find one’s complement Add 1 to the 1’s complement

Example: Suppose we're working with 8 bits and we want to find how -28 would be expressed in two’s complement notation: STEP 1: First we write out 28 in binary form. 28 = 00011100 STEP 2: Then we invert the digits. 0 becomes 1, 1 becomes 0. Therefore the 1’s Complement of: 00011100 = 11100011 STEP 3: Add 1 to the 1’s Complement: 11100011 + 1 = 11100100 Therefore, -28 = 11100100

QUESTIONS Represent the following numbers in binary (using 8 bits) in 2’s complement: -108 6 -123

QUESTIONS Find the two’s complement representation of the following using 8 bits: 1011 11001

HOME-WORK Represent the following numbers in binary (using 8 bits) in 2’s complement: -64 7 Find the two’s complement representation of the following using 8 bits: 101010 11101

HOME-WORK Cont’d Read Pg 62 -63 (Log On to IT for CSEC 2nd Ed.)- BCD and Data Representation. Review Sign and Magnitude, 1’s Complement and 2’s Complement and Addition for Test next day!

Adding a negative number- using Two’s complement Example: Find the value of 9-6 using four-bit two’s complement binary. 9 – 6 could also be written as 9 + (-6)

1. Convert 9 to binary 9= 10012 2. Find the Two’s Complement of -6: 6= 0110 1’s Complement = 1001 Add 1 = 1001 +1 = 1010 Therefore -6 (2’s Comp.) = 1010 3. Add 9 to -6 = 1001 + 1010 = 10011 Discard the extra bit because we are using 4-bit representation. 4. 9-6 (using two’s compl.) = 00112

HOME-WORK Find the value of the following using eight-bit two’s complement: 15-8 50-25 -8+12 Read Pg. 62-63 (Log On to IT for CSEC, 2nd Ed.: BCD and ASCII

BINARY CODED DECIMAL- BCD BCD is an encoding system for decimal numbers in which each digit is represented by its own binary sequence. In BCD, a digit is usually represented by four bits which, in general, represent the decimal digits 0 through 9. Other bit combinations are sometimes used for a sign.

BCD 0000 1 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 + 1010 - 1011

Example 1: What is the BCD representation of -325? - = 1011 3 = 0011 2 = 0010 5 = 0101 Therefore 325 = 1011 0011 0010 0101

Example 2: What is the BCD representation of 325? + = 1010 3 = 0011 2 = 0010 5 = 0101 Therefore -325 = 1010 0011 0010 0101

Questions: What is the BCD representation of the following decimal numbers? 56 -63 -4 1005

DATA REPRESENTATION Two of the most common codes used to represent character sets in computers are: 1. ASCII (American Standard Code for Information Interchange). 2. EBCIDIC (Extended Binary Coded Decimal Interchange Code).

ASCII CODE 65-90 A to Z 97-122 a to z

Example 1: The ASCII code for the letter A is 1000001. Determine the 7-bit ASCII code for the letter G. A = 1000001 G is the 6th letter from A 6 = 110 Therefore: 1000001 + 110= 1000111 *see text book for other methods

Questions 1. What letter is represented by the binary representation 1001101 using ASCII? 2. The ASCII representation for the letter t is 1110100. What is the ASCII representation of the letter y? 3. Determine the ASCII representation of : (i) G (ii) d (iii) R