Download presentation
Presentation is loading. Please wait.
1
Lecture No. 4 Number Systems
Asalam O Aleikum students. I am Waseem Ikram. This is the fourth lecture in a series of 45 lectures on Digital Logic Design. In the last lecture we discussed the 32-bit floating point single precision format for representing very small, very large numbers and numbers having an integer part and a fraction part.
2
32-bit f.p. number (recap) 32-bit Floating point format Sign bit 1
Exponent bits 8 Mantissa bits 23 Exponent represented as Biased 127
3
Range of f.p. numbers (recap)
Largest positive/negative number 2127 Smallest positive/negative number 2-126 The number Zero Exponent = Mantissa = The number infinite Exponent = Mantissa =
4
Arithmetic operations on floating point numbers
Addition Adding mantissas after adjusting exponents Subtraction Subtracting mantissas after adjusting exponents Multiplication Multiplying mantissas and adding exponents Division Dividing mantissas and subtracting exponents Addition and Subtraction can be performed by adjusting the decimal point such that the two exponent values become equal. Adding the mantissa parts keeping the exponent constant adds two f.p numbers Subtracting the mantissa parts keeping the exponent constant subtracts two f.p. numbers Multiplication is performed by multiplying the mantissas together and adding the exponents Division is performed by dividing the mantissa parts and subtracting the exponents
5
64-bit f.p. number (recap) 64-bit Double-Precision floating Point format Sign bit 1 Exponent bits 11 Mantissa bits 52 Exponent represented as Biased 1023 The 32-bit and 64-bit floating point format basically codes a very large or a very small number using 32 or 64 bits respectively. The digital system that uses this format to represent numbers has to be told before hand that the number is in a 32-bit or 64-bit floating point format. Otherwise it might handle the 32-bit number as an unsigned or signed 32-bit number. How is the digital system informed before hand the format or the type of the number being used? In a Computer, the program instructions inform the computer about the type of the number being used. How? At the start of the program all the variables that are being used in the program are defined and declared as integers or real numbers etc. Thus when ever the variable is accessed the computer handles the number as of the type defined in the declaration.
6
f.p. numbers (recap) How do systems differentiate between number representations? Defining and Declaring Data Types. The 32-bit and 64-bit floating point format basically codes a very large or a very small number using 32 or 64 bits respectively. The digital system that uses this format to represent numbers has to be told before hand that the number is in a 32-bit or 64-bit floating point format. Otherwise it might handle the 32-bit number as an unsigned or signed 32-bit number. How is the digital system informed before hand the format or the type of the number being used? In a Computer, the program instructions inform the computer about the type of the number being used. How? At the start of the program all the variables that are being used in the program are defined and declared as integers or real numbers etc. Thus when ever the variable is accessed the computer handles the number as of the type defined in the declaration.
7
Hexadecimal Numbers (recap)
Hexadecimal Number System Base 16 number system 0 to F Used to represent large binary numbers
8
Counting in Hexadecimal (recap)
Binary Hexadecimal 0000 8 1000 1 0001 9 1001 2 0010 10 1010 A 3 0011 11 1011 B 4 0100 12 1100 C 5 0101 13 1101 D 6 0110 14 1110 E 7 0111 15 1111 F
9
Binary-Hexadecimal conversion (recap)
Binary to Hexadecimal Conversion D B Hexadecimal to Binary Conversion FD13
10
Hexadecimal-decimal conversion (recap)
Hexadecimal to Decimal Conversion Indirect Method Hexadecimal →Binary → Decimal Sum-of-Weights
11
Decimal-Hexadecimal Conversion (recap)
Decimal to Hexadecimal Conversion Indirect Method Decimal →Binary → Hexadecimal Repeated Division by 16
12
Hexadecimal Arithmetic (recap)
Hexadecimal Addition Carry generated Hexadecimal Subtraction Borrow weight 16
13
Octal Number System Base 8 0, 1, 2, 3, 4, 5, 6, 7
Representing Binary in compact form = Not commonly used in the presence of Hexadecimal Number System
14
Counting in Octal Octal digit represented by a 3-bit binary
Decimal 8 represented by 2-digit Octal
15
Counting in Octal Decimal Binary Octal 000 1 001 2 010 3 011 4 100 5
000 1 001 2 010 3 011 4 100 5 101 6 110 7 111 The table shows the decimal and binary equivalents of the Octal digits 0 to 7
16
Counting in Octal Decimal Octal 8 10 16 20 24 30 9 11 17 21 25 31 12
18 22 26 32 13 19 23 27 33 14 28 34 15 29 35 36 37 The table shows Octal equivalents of decimal numbers 8 to 31 Octal Number 7 has the largest value. To represent decimal 8 a 2-digit octal number is used. The most significant digit is a 1. The least significant digit is a 0. Decimal Numbers 8 to 15 are represented by the 2-digit octal combination. The most significant digit is fixed at 1. The least significant digit varies from 0 to 7 Similarly the decimal numbers 16 to 23 are represented by the 2-digit octal combination of 2 as the most significant digit and the least significant digit varying from 0 to 7.
17
Binary-Octal Conversion
Binary to Octal Conversion Octal to Binary Conversion
18
Octal-Decimal Conversion
Octal to Decimal Conversion Indirect Method Octal →Binary → Decimal Sum-of-Weights
19
Decimal-Octal Conversion
Decimal to Octal Conversion Indirect Method Decimal →Binary → Octal Repeated Division by 8
20
Octal Addition & Subtraction
Carry generated Octal Subtraction Borrow weight 8
21
Binary to Octal Conversion
Consider the 21-bit binary string which is to be converted into Octal The 21-bit binary string is divided into groups of 3-bits starting from the least significant bit 7 groups of 3-bits are formed. In the next step each group of 3-bits is replaced by the equivalent Octal digit. The result is a 7-digit Octal Number. Consider the 13-bit binary string which is to be converted into Octal The 13-bit binary string is divided into groups of 3-bits starting from the least significant bit 4 groups of 3-bits are formed and an incomplete 5th group with a single bit. Two most significant zero bits are appended to complete the group. Each 3-bit group is replaced by the equivalent Octal digit to complete the conversion
22
Octal to Binary Conversion
1726 Consider the 4 digit Octal number which is to be converted into Binary Each Octal digit is replaced by its equivalent 3-bit binary number. Thus Octal 1 is replaced by 001 Octal 7 is replaced by 111 Octal 2 is replaced by 010 And Octal 6 is replaced by 110
23
Sum-of-Weights 4037 (4 x 83) + (0 x 82) + (3 x 81) + (7 x 80)
2079 Consider the Sum-of-Weights method to convert Octal 4037 to Decimal An expression in terms of the base number 8 and weights is written The expression is solved to give four sum terms 2048, 0, 24 and 7 The four terms are added to result in the number 2079 the decimal equivalent of Octal 4037
24
Repeated Division by 8 Number Quotient Remainder 2079 259 7 (O0) 32
4 (O2) (O3) Consider the Repeated division by 8 method to convert Decimal 2079 into Octal The decimal number 2079 is divided by 8 which results in a quotient value of 259 and the remainder 7 The remainder 7 is noted and the quotient 259 is divided by 8. 259 divided by 8 results in a quotient value of 32 and a remainder value of 3. The remainder 3 is noted and the quotient 32 is divided by 8. 32 divided by 8 results in a quotient value of 4 and a remainder 0. The remainder 0 is noted and the quotient value 4 is divided by 8. This results in a quotient value of 0 which indicates the completion of the repeated division by 8 method. The remainder 4 and the three remainders noted earlier represent the 4 digit Octal Number 4037
25
Octal Addition Carry 1 7602 14573 Consider the addition of Octal numbers 7602 and 4771 The two octal numbers are added by first adding the two least significant octal digits 2 and 1. The sum of the two octal digits is 3. The next two octal digits 0 and 7 are added next and the result is 7. The octal digits 6 and 7 are added next. The answer in decimal is 13 which is represented as 15 in Octal. Thus the sum is Octal 5 and a carry of 1 is carried over to the most significant digit. Adding the most significant octal digits 7 and 4 along with the carry 1 results in decimal 12 which is equivalent to Octal 14. The sum is 4 and carry of 1 is carried over to the 4th octal digit position. The sum is Octal.
26
Octal Subtraction Borrow 11 7602 - 4771 2611
2611 Consider the Subtraction of Octal 4771 from Octal 7602. The two numbers are subtracted by first subtracting the least significant digits Octal 1 from Octal 2. The difference is Octal 1. Next Octal 7 is subtracted from Octal 0. A borrow is required from the next most significant digit. Borrowing a 1 means subtracting Octal 7 from Octal 10 which is decimal 8. The Octal number 7 is subtracted from Octal 5 instead of Octal 6 in the 2nd digit position as a 1 had been borrowed from Octal 6. To subtract Octal 7 from Octal 5 requires another borrow from the most significant digit 7. Thus subtracting Octal 7 from Octal 15 results in a difference of 6. The most significant digits are subtracted to result in 2. The difference of Octal 7602 and 4771 is Octal 2611.
27
Alternate Representations
Excess Code BCD Code Gray Code There are many different ways to represent binary numbers, other than the 4 representation that we have discussed. Many of these alternate representations are used to support specific applications and requirements.
28
Excess Code A bias is added to Binary Code
Used by floating point numbers
29
Excess-8 Code Decimal 2’s Comp. Excess-8 2’s Comp. 0000 1000 -8 1 0001
0000 1000 -8 1 0001 1001 -7 2 0010 1010 -6 3 0011 1011 -5 4 0100 1100 -4 5 0101 1101 -3 6 0110 1110 -2 7 0111 1111 -1 Consider the decimal number range +7 to -8. These positive and negative decimal numbers can be represented by the 2’s complement representation. The magnitude of positive and negative numbers can not be easily compared if the numbers are represented in 2’s complement form. The decimal number range +7 to -8 is represented using an Excess-8 code that assigns 0000 to -8 the lowest number in the range and 1111 to +7 the highest number in the range. Excess-8 code is obtained by adding a number to the lowest number -8 in the range such that the result is zero. The number is 8. The number 8 is added to all the remaining decimal numbers from -7 up to the highest number +7. The resulting code is Excess-8 code or Biased 8 code.
30
BCD (Binary Coded Decimal) Code
Binary Code to represent decimal digits 0-9 Used by Decimal Number Displays Most digital systems display a count value or the time in decimal on 7-segment LED display panels. Since the numbers displayed are in decimal, therefore the binary code used to display the decimal numbers is designed to represent a single digit. Consider a 2-digit 7-segment display that can display a count value from 0 to 99. To display the two decimal digits two separate binary codes are applied at the 7-segment display circuit inputs. Since each binary code has to specify a digit between 0 and 9 therefore only 10 different binary codes are required. How many binary bits are required to represent 10 unique codes? A 4-bit binary code allows 16 different binary combinations to be represented. Only the first 10, 4-bit binary codes are used, the remaining 6 codes are not used. Thus displaying a 2-digit decimal number 79 would require the digital system to generate two BCD numbers 0111 and 1001 respectively
31
BCD (Binary Coded Decimal) Code
0000 5 0101 1 0001 6 0110 2 0010 7 0111 3 0011 8 1000 4 0100 9 1001 The Table shows the valid BCD codes. A 4-bit binary code can represent up to 16 different values. The 4-bit BCD code represents decimal digits 0 to 9 in binary. Thus the binary code 1010, 1011, 1100, 1101, 1110 and 1111 are considered to be invalid BCD codes.
32
BCD Addition 1100 is illegal BCD number Consider the addition of two, 2-digit BCD numbers 23 and 45 BCD numbers are added using Binary addition method, resulting in 68 Consider the addition of two, 2-digit BCD numbers 23 and 49 Adding least significant digits 3 and 9 results in 12 represented as 1100. 1100 is an invalid BCD digit. Secondly adding 3 and 9 in decimal should result in 2 as the sum and 1 as the carry. The BCD result is equivalent to 62 which is incorrect as the carry generated by the addition of the least significant digits has not been considered.
33
BCD Addition Add a 0110 (6) to an invalid BCD number
Carry added to the most significant BCD digit 0110 When addition of BCD digits results in an invalid BCD number or a carry. The number 0110 (6 decimal) is added to the result. Reconsidering the addition of BCD 23 and 49. The addition of digits 3 and 9 results in 1100 an invalid BCD number A 0110 decimal 6 is added which results in 0010 and a carry which is added to 0110 to result in 0111
34
Gray Code Binary Code more than 1 bit change
Electromechanical applications of digital systems restrict bit change to 1 Shaft encoders Braking Systems Un-Weighted Code
35
Gray Code Decimal Gray Binary 000 1 001 2 011 010 3 4 110 100 5 111
000 1 001 2 011 010 3 4 110 100 5 111 101 6 7 Consider the 3-bit binary code and the 3-bit Gray code representing the decimal numbers 0 to 7. The binary code is a positional code and the three bits starting from the least significant bit have the weights 1,2 and 4. The Gray Code is not a positional code. However, the change from one value to the next using the Gray code guarantees a single bit change.
36
Gray Code Application Consider the example of shaft encoders that best explain the utility of the Gray Code. The Diagram shows a disk connected to the shaft of a rotating machine. The shaded areas on the disk indicate conducting strips connected to +5 volts. The non-shaded area indicate a non-conducting strips. Three stationary brushes A, B and C touch the surface of the rotating disk. The three brushes are connected to three LED lamps through wires. As the disk rotates the brushes come in contact with the conducting area and the insulated area. The three LEDs display the position of the rotating shaft in terms of 3-bit numbers. Consider the disk on the left. If the disk on the left rotates in the anti-clockwise direction by 450 the Brush A comes in contact with the conducting strip at 5 volts, which turns on the LED indicating Binary 001. If the disk continuous its rotation, after a rotation of another 450, brush B comes in contact with the conducting strip and brush A comes in contact with the non-conducting strip. Thus LED connected to brush B lights up indicating binary 010. Thus at any instant of time, the LEDs indicate the angular position of the rotating shaft in steps of 450 Assume that the three brushes A, B and C are not aligned properly and Brush B is slightly ahead of brushes A and C. Now if the disk rotates 900 from its start position. Brush A is in contact with the conducting strip, Brush B due to its misalignment is in contact with the conducting strip and brush C is in contact with the insulated strip. Thus when the disk rotates the LEDs will show a 001,followed by a 011 for a short duration when the disk rotates from 900 to 910 and then to 010. Thus due to misalignment the count value jumped from 1 to 3 and then back to 2. Consider the disk shown on the right. The conducting and non-conducting strips follow a Gray Code pattern 000, 001, 011, 010, 110, 111, 101 and 100 representing decimal 0, 1, 2, 3, 4, 5, 6 and 7. Now even if the brushes are misaligned, the LEDs would always display the correct count value.
37
Alphanumeric Code Numbers, Characters, Symbols ASCII 7-bit Code
American Standard Code for Information Interchange 10 Numbers (0-9) 26 Lower Case Characters (a-z) 26 Upper Case Characters (A-Z) 32 Control Characters Punctuation and Symbols
38
Alphanumeric Code Extended ASCII 8-bit Code
Additional 128 Graphic characters Unicode 16-bit Code
39
ASCII Code Numbers 0 to 9 ASCII 0110000 (30h) to 0111001 (39h)
Alphabets a to z ASCII (61h) to (7Ah) Alphabets A to Z ASCII (41h) to (5Ah) Control Characters ASCII (0h) to (1Fh) Consider some of the ASCII codes that represent the numbers 0 to 9 The ASCII code which is also equivalent to 30h represents 0 The ASCII code which is also equivalent to 31h represents 1 The ASCII code which is also equivalent to 39h represents 9 ASCII codes (61h) to (7Ah) represent lower case alphabets a to z ASCII codes (41h) to (5Ah) represent upper case alphabets A to Z The 32 control characters are represented by ASCII code (0h) to (1Fh)
40
Error Detection Digital Systems are very Reliable
Errors during storage or transmission Parity Bit Even Parity Odd Parity
41
Odd Parity Error Detection
Original data With Odd Parity 1-bit error Number of 1s even indicates 1-bit error 2-bit error Number of 1s odd no error indicated 3-bit error Number of 1s even indicates error
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.