Presentation is loading. Please wait.

Presentation is loading. Please wait.

BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems.

Similar presentations


Presentation on theme: "BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems."— Presentation transcript:

1 BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems

2 BEE1244 Digital System and Electronics Overview °The design of computers It all starts with numbers Building circuits Building computing machines °Digital systems °Understanding decimal numbers °Binary and octal numbers The basis of computers! °Conversion between different number systems

3 BEE1244 Digital System and Electronics Overview °Hexadecimal numbers Related to binary and octal numbers °Conversion between hexadecimal, octal and binary °Value ranges of numbers °Representing positive and negative numbers °Creating the complement of a number Make a positive number negative (and vice versa) °Why binary?

4 BEE1244 Digital System and Electronics Digital Computer Systems °Digital systems consider discrete amounts of data. °Examples 26 letters in the alphabet 10 decimal digits °Larger quantities can be built from discrete values: Words made of letters Numbers made of decimal digits (e.g. 239875.32) °Computers operate on binary values (0 and 1) °Easy to represent binary values electrically Voltages and currents. Can be implemented using circuits Create the building blocks of modern computers

5 BEE1244 Digital System and Electronics Understanding Decimal Numbers °Decimal numbers are made of decimal digits: (0,1,2,3,4,5,6,7,8,9) °But how many items does a decimal number represent? 8653 = 8x10 3 + 6x10 2 + 5x10 1 + 3x10 0 °What about fractions? 97654.35 = 9x10 4 + 7x10 3 + 6x10 2 + 5x10 1 + 4x10 0 + 3x10 -1 + 5x10 -2 In formal notation -> (97654.35) 10 °Why do we use 10 digits, anyway?

6 BEE1244 Digital System and Electronics Understanding Octal Numbers °Octal numbers are made of octal digits: (0,1,2,3,4,5,6,7) °How many items does an octal number represent? (4536) 8 = 4x8 3 + 5x8 2 + 3x8 1 + 6x8 0 = (2398) 10 °What about fractions? (465.27) 8 = 4x8 2 + 6x8 1 + 5x8 0 + 2x8 -1 + 7x8 -2 = (309.359375) 10 °Octal numbers don’t use digits 8 or 9 °Who would use octal number, anyway?

7 BEE1244 Digital System and Electronics Understanding Binary Numbers °Binary numbers are made of binary digits (bits): 0 and 1 °How many items does an binary number represent? (1011) 2 = 1x2 3 + 0x2 2 + 1x2 1 + 1x2 0 = (11) 10 °What about fractions? (110.10) 2 = 1x2 2 + 1x2 1 + 0x2 0 + 1x2 -1 + 0x2 -2 = (6.5) 10 °Groups of eight bits are called a byte (11001001) 2 °Groups of four bits are called a nibble. (1101) 2

8 BEE1244 Digital System and Electronics Why Use Binary Numbers? °Easy to represent 0 and 1 using electrical values. °Possible to tolerate noise. °Easy to transmit data °Easy to build binary circuits. AND Gate 1 0 0

9 BEE1244 Digital System and Electronics Conversion Between Number Bases Decimal(base 10) Octal(base 8) Binary(base 2) Hexadecimal (base16) °Learn to convert between bases. °Already demonstrated how to convert from binary to decimal. °Hexadecimal described in next section.

10 BEE1244 Digital System and Electronics Convert an Integer from Decimal to Another Base 1.Divide decimal number by the base (e.g. 2) 2.The remainder is the lowest-order digit 3.Repeat first two steps until no divisor remains. For each digit position: Example for (13) 10: Integer Quotient 13/2 = 6 + ½ a 0 = 1 6/2 = 3 + 0 a 1 = 0 3/2 = 1 + ½ a 2 = 1 1/2 = 0 + ½ a 3 = 1 RemainderCoefficient Answer (13) 10 = (a 3 a 2 a 1 a 0 ) 2 = (1101) 2

11 BEE1244 Digital System and Electronics Convert an Fraction from Decimal to Another Base 1.Multiply decimal number by the base (e.g. 2) 2.The integer is the highest-order digit 3.Repeat first two steps until fraction becomes zero. For each digit position: Example for (0.625) 10: Integer 0.625 x 2 = 1 + 0.25 a -1 = 1 0.250 x 2 = 0 + 0.50 a -2 = 0 0.500 x 2 = 1 + 0 a -3 = 1 FractionCoefficient Answer (0.625) 10 = (0.a -1 a -2 a -3 ) 2 = (0.101) 2 http://www.rapidtables.com/convert/number/octal-to-decimal.htm

12 BEE1244 Digital System and Electronics The Growth of Binary Numbers n2n2n 02 0 =1 1 2 1 =2 2 2 2 =4 3 2 3 =8 4 2 4 =16 5 2 5 =32 6 2 6 =64 72 7 =128 n2n2n 82 8 =256 9 2 9 =512 10 2 10 =1024 11 2 11 =2048 12 2 12 =4096 20 2 20 =1M 30 2 30 =1G 402 40 =1T Mega Giga Tera

13 BEE1244 Digital System and Electronics Binary Addition °Binary addition is very simple. °This is best shown in an example of adding two binary numbers… 1 1 1 1 0 1 + 1 0 1 1 1 --------------------- 0 1 0 1 1 1111 1100 carries

14 BEE1244 Digital System and Electronics Binary Subtraction °We can also perform subtraction (with borrows in place of carries). °Let’s subtract (10111) 2 from (1001101) 2 … 1 10 0 10 10 0 0 10 1 0 0 1 1 0 1 - 1 0 1 1 1 ------------------------ 1 1 0 1 1 0 borrows

15 BEE1244 Digital System and Electronics Binary Multiplication °Binary multiplication is much the same as decimal multiplication, except that the multiplication operations are much simpler… 1 0 1 1 1 X 1 0 1 0 ----------------------- 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 1 0 1 1 1 ----------------------- 1 1 1 0 0 1 1 0

16 BEE1244 Digital System and Electronics Convert an Integer from Decimal to Octal 1.Divide decimal number by the base (8) 2.The remainder is the lowest-order digit 3.Repeat first two steps until no divisor remains. For each digit position: Example for (175) 10: Integer Quotient 175/8 = 21 + 7/8 a 0 = 7 21/8 = 2 + 5/8 a 1 = 5 2/8 = 0 + 2/8 a 2 = 2 RemainderCoefficient Answer (175) 10 = (a 2 a 1 a 0 ) 2 = (257) 8

17 BEE1244 Digital System and Electronics Convert an Fraction from Decimal to Octal 1.Multiply decimal number by the base (e.g. 8) 2.The integer is the highest-order digit 3.Repeat first two steps until fraction becomes zero. For each digit position: Example for (0.3125) 10: Integer 0.3125 x 8 = 2 + 5 a -1 = 2 0.5000 x 8 = 4 + 0 a -2 = 4 FractionCoefficient Answer (0.3125) 10 = (0.24) 8

18 BEE1244 Digital System and Electronics Understanding Hexadecimal Numbers °Hexadecimal numbers are made of 16 digits: (0,1,2,3,4,5,6,7,8,9,A, B, C, D, E, F) °How many items does an hex number represent? (3A9F) 16 = 3x16 3 + 10x16 2 + 9x16 1 + 15x16 0 = 14999 10 °What about fractions? (2D3.5) 16 = 2x16 2 + 13x16 1 + 3x16 0 + 5x16 -1 = 723.3125 10 °Note that each hexadecimal digit can be represented with four bits. (1110) 2 = (E) 16 °Groups of four bits are called a nibble. (1110) 2

19 BEE1244 Digital System and Electronics Putting It All Together °Binary, octal, and hexadecimal similar °Easy to build circuits to operate on these representations °Possible to convert between the three formats

20 BEE1244 Digital System and Electronics Converting Between Base 16 and Base 2 °Conversion is easy!  Determine 4-bit value for each hex digit °Note that there are 2 4 = 16 different values of four bits °Easier to read and write in hexadecimal. °Representations are equivalent! 3A9F 16 = 0011 1010 1001 1111 2 3A9F

21 BEE1244 Digital System and Electronics Converting Between Base 16 and Base 8 1.Convert from Base 16 to Base 2 2.Regroup bits into groups of three starting from right 3.Ignore leading zeros 4.Each group of three bits forms an octal digit. 35237 8 = 011 101 010 011 111 2 52373 3A9F 16 = 0011 1010 1001 1111 2 3A9F

22 BEE1244 Digital System and Electronics How To Represent Signed Numbers Plus and minus sign used for decimal numbers: 25 (or +25), -16, etc..For computers, desirable to represent everything as bits. Three types of signed binary number representations: signed magnitude, 1’s complement, 2’s complement. In each case: left-most bit indicates sign: positive (0) or negative (1). Consider signed magnitude: 00001100 2 = 12 10 Sign bitMagnitude 10001100 2 = -12 10 Sign bitMagnitude

23 BEE1244 Digital System and Electronics One’s Complement Representation The one’s complement of a binary number involves inverting all bits. 1’s comp of 00110011 is 11001100 1’s comp of 10101010 is 01010101 For an n bit number N the 1’s complement is (2 n -1) – N. Called diminished radix complement by Mano since 1’s complement for base (radix 2). To find negative of 1’s complement number take the 1’s complement. 00001100 2 = 12 10 Sign bitMagnitude 11110011 2 = -12 10 Sign bitMagnitude

24 BEE1244 Digital System and Electronics Two’s Complement Representation The two’s complement of a binary number involves inverting all bits and adding 1. 2’s comp of 00110011 is 11001101 2’s comp of 10101010 is 01010110 For an n bit number N the 2’s complement is (2 n -1) – N + 1. Called radix complement by Mano since 2’s complement for base (radix 2). To find negative of 2’s complement number take the 2’s complement. 00001100 2 = 12 10 Sign bitMagnitude 11110100 2 = -12 10 Sign bitMagnitude

25 BEE1244 Digital System and Electronics Two’s Complement Shortcuts °Algorithm 1 – Simply complement each bit and then add 1 to the result. Finding the 2’s complement of (01100101) 2 and of its 2’s complement… N = 01100101[N] = 10011011 10011010 01100100 + 1 + 1 --------------- 10011011 01100101 °Algorithm 2 – Starting with the least significant bit, copy all of the bits up to and including the first 1 bit and then complementing the remaining bits. N = 0 1 1 0 0 1 0 1 [N] = 1 0 0 1 1 0 1 1

26 BEE1244 Digital System and Electronics Finite Number Representation °Machines that use 2’s complement arithmetic can represent integers in the range -2 n-1 <= N <= 2 n-1 -1 where n is the number of bits available for representing N. Note that 2 n-1 -1 = (011..11) 2 and –2 n-1 = (100..00) 2 oFor 2’s complement more negative numbers than positive. oFor 1’s complement two representations for zero. oFor an n bit number in base (radix) z there are z n different unsigned values. (0, 1, …z n-1 )

27 BEE1244 Digital System and Electronics 1’s Complement Addition °Using 1’s complement numbers, adding numbers is easy. °For example, suppose we wish to add +(1100) 2 and +(0001) 2. °Let’s compute (12) 10 + (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 1’s comp. (1) 10 = +(0001) 2 = 00001 2 in 1’s comp. 0 1 1 0 0 +0 0 0 0 1 -------------- 0 0 1 1 0 1 0 -------------- 0 1 1 0 1 Add carry Final Result Step 1: Add binary numbers Step 2: Add carry to low-order bit Add

28 BEE1244 Digital System and Electronics 1’s Complement Subtraction °Using 1’s complement numbers, subtracting numbers is also easy. °For example, suppose we wish to subtract +(0001) 2 from +(1100) 2. °Let’s compute (12) 10 - (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 1’s comp. (-1) 10 = -(0001) 2 = 11110 2 in 1’s comp. 0 1 1 0 0 -0 0 0 0 1 -------------- 0 1 1 0 0 +1 1 1 1 0 -------------- 1 0 1 0 1 0 1 -------------- 0 1 0 1 1 Add carry Final Result Step 1: Take 1’s complement of 2 nd operand Step 2: Add binary numbers Step 3: Add carry to low order bit 1’s comp Add

29 BEE1244 Digital System and Electronics 2’s Complement Addition °Using 2’s complement numbers, adding numbers is easy. °For example, suppose we wish to add +(1100) 2 and +(0001) 2. °Let’s compute (12) 10 + (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 2’s comp. (1) 10 = +(0001) 2 = 00001 2 in 2’s comp. 0 1 1 0 0 +0 0 0 0 1 -------------- 0 0 1 1 0 1 Final Result Step 1: Add binary numbers Step 2: Ignore carry bit Add Ignore

30 BEE1244 Digital System and Electronics 2’s Complement Subtraction °Using 2’s complement numbers, follow steps for subtraction °For example, suppose we wish to subtract +(0001) 2 from +(1100) 2. °Let’s compute (12) 10 - (1) 10. (12) 10 = +(1100) 2 = 01100 2 in 2’s comp. (-1) 10 = -(0001) 2 = 11111 2 in 2’s comp. 0 1 1 0 0 -0 0 0 0 1 -------------- 0 1 1 0 0 +1 1 1 1 1 -------------- 1 0 1 0 1 1 Final Result Step 1: Take 2’s complement of 2 nd operand Step 2: Add binary numbers Step 3: Ignore carry bit 2’s comp Add Ignore Carry

31 BEE1244 Digital System and Electronics 2’s Complement Subtraction: Example #2 °Let’s compute (13) 10 – (5) 10. (13) 10 = +(1101) 2 = (01101) 2 (-5) 10 = -(0101) 2 = (11011) 2 °Adding these two 5-bit codes… °Discarding the carry bit, the sign bit is seen to be zero, indicating a correct result. Indeed, (01000) 2 = +(1000) 2 = +(8) 10. 0 1 1 0 1 +1 1 0 1 1 -------------- 10 1 0 0 0 carry

32 BEE1244 Digital System and Electronics 2’s Complement Subtraction: Example #3 °Let’s compute (5) 10 – (12) 10. (-12) 10 = -(1100) 2 = (10100) 2 (5) 10 = +(0101) 2 = (00101) 2 °Adding these two 5-bit codes… °Here, there is no carry bit and the sign bit is 1. This indicates a negative result, which is what we expect. (11001) 2 = -(7) 10. 0 0 1 0 1 +1 0 1 0 0 -------------- 1 1 0 0 1

33 BEE1244 Digital System and Electronics Homework Q2:Perform binary subtraction for the following: °(i) 110101 – 100101 using 1’s complement °(ii) 101011 – 111001 using 1’s complement °(iii) 10110 – 1101 using 2’s complement °(iv) 10101010 – 00111000 using 2’s complement

34 BEE1244 Digital System and Electronics Homework Q1: Convert the following BinaryOctalDecimalHex 10011010 2705 3BC Q2 : Perform binary subtraction for the following: °(i) 110101 – 100101 using 1’s complement °(ii) 101011 – 111001 using 1’s complement °(iii) 10110 – 1101 using 2’s complement °(iv) 10101010 – 00111000 using 2’s complement

35 BEE1244 Digital System and Electronics Binary Coded Decimal °Binary coded decimal (BCD) represents each decimal digit with four bits Ex. 0011 0010 1001 = 329 10 °This is NOT the same as 001100101001 2 °Why do this? Because people think in decimal. Digit BCD Code Digit BCD Code 0000050101 1000160110 2001070111 3001181000 4010091001 3 2 9

36 BEE1244 Digital System and Electronics Putting It All Together °BCD not very efficient °Used in early computers (40s, 50s) °Used to encode numbers for seven- segment displays. °Easier to read?

37 BEE1244 Digital System and Electronics Gray Code °Gray code is not a number system. It is an alternate way to represent four bit data °Only one bit changes from one decimal digit to the next °Useful for reducing errors in communication. °Can be scaled to larger numbers. DigitBinary Gray Code 0 0000 1 0001 2 0010 0011 3 0010 4 0100 0110 5 0101 0111 6 0110 0101 7 0111 0100 8 1000 1100 9 1001 1101 10 1010 1111 11 1011 1110 12 1100 1010 13 1101 1011 14 1110 1001 15 1111 1000

38 BEE1244 Digital System and Electronics ASCII Code °American Standard Code for Information Interchange °ASCII is a 7-bit code, frequently used with an 8 th bit for error detection (more about that in a bit). CharacterASCII (bin) ASCII (hex) DecimalOctal A10000014165101 B10000104266102 C10000114367103 … Z a … 1 ‘

39 BEE1244 Digital System and Electronics ASCII Codes and Data Transmission °ASCII Codes °A – Z (26 codes), a – z (26 codes) °0-9 (10 codes), others (@#$%^&*….) °Complete listing °Transmission susceptible to noise °Typical transmission rates (1500 Kbps, 56.6 Kbps) °How to keep data transmission accurate?

40 BEE1244 Digital System and Electronics Parity Codes °Parity codes are formed by concatenating a parity bit, P to each code word of C. °In an odd-parity code, the parity bit is specified so that the total number of ones is odd. °In an even-parity code, the parity bit is specified so that the total number of ones is even. Information BitsP 1 1 0 0 0 0 1 1  Added even parity bit 0 1 0 0 0 0 1 1  Added odd parity bit

41 BEE1244 Digital System and Electronics Parity Code Example °Concatenate a parity bit to the ASCII code for the characters 0, X, and = to produce both odd-parity and even-parity codes. CharacterASCII Odd-Parity ASCII Even-Parity ASCII 001100001011000000110000 X10110000101100011011000 =01111001011110000111100

42 BEE1244 Digital System and Electronics Binary Data Storage Binary cells store individual bits of data Multiple cells form a register. Data in registers can indicate different values Hex (decimal) BCD ASCII Binary Cell 00101011

43 BEE1244 Digital System and Electronics Register Transfer °Data can move from register to register. °Digital logic used to process data °We will learn to design this logic Register ARegister B Register C Digital Logic Circuits

44 BEE1244 Digital System and Electronics Transfer of Information °Data input at keyboard °Shifted into place °Stored in memory NOTE: Data input in ASCII

45 BEE1244 Digital System and Electronics Building a Computer °We need processing °We need storage °We need communication °You will learn to use and design these components.

46 BEE1244 Digital System and Electronics Summary °Binary numbers are made of binary digits (bits) °Binary and octal number systems °Conversion between number systems °Addition, subtraction, and multiplication in binary

47 BEE1244 Digital System and Electronics Summary °Binary numbers can also be represented in octal and hexadecimal °Easy to convert between binary, octal, and hexadecimal °Signed numbers represented in signed magnitude, 1’s complement, and 2’s complement °2’s complement most important (only 1 representation for zero). °Important to understand treatment of sign bit for 1’s and 2’s complement.

48 BEE1244 Digital System and Electronics Summary °Although 2’s complement most important, other number codes exist °ASCII code used to represent characters (including those on the keyboard) °Registers store binary data °Next time: Building logic circuits!


Download ppt "BEE1244 Digital System and Electronics BEE1244 Digital System and Electronic Chapter 2 Number Systems."

Similar presentations


Ads by Google