Professional Documents
Culture Documents
Recap
Number System Conversion
◦ Sum-of-Weights for converting to decimal
◦ Repeated division for converting from decimal
Binary Arithmetic
◦ Similar to Decimal Arithmetic
◦ Multiplying by a constant by shifting left
◦ Dividing by a constant by shifting right
Representing Numbers
◦ Unsigned
◦ Signed Magnitude
◦ 2’s Complement
•Informing the digital system beforehand to deal with a number as signed or unsigned is
inconvenient
•Signed binary numbers are represented in their 2’s complement form.
•A 2’s complement of a binary number is achieved by first taking the 1’s complement of a
number followed by its 2’s complement.
•The 1’s complement of a binary number is obtained by simply inverting each bit.
•The 2’s complement of a binary number is obtained by adding a 1 to the 1’s complement of the
original number.
•In a 2’s complement form all negative binary numbers are represented in their 2’s complement
form
•All such negative numbers have their most significant bit set to 1 signifying a negative number.
•All positive numbers are represented in their original form.
•Their most significant bit is a 0 specifying a positive number.
Slide 4
0101 +5 0101 +5
0010 +2 1110 -2
0111 +7 10011 +3
1011 -5 1011 -5
1110 -2 0010 +2
11001-7 1101 -3
1011 -5 1101 -5
1110 -2 1010 -2
11001 -7 10111 -7
•Refer to the table of Signed Magnitude and 2’s complement representation of decimal values -
8 to 7 discussed in the last lecture.
•Compare the addition operation using 2’s complement and signed number representation.
•The results for addition using 2’s complement are compatible with the decimal numbers
represented in their 2’s complement form.
•For example, adding +5 and +2 results in +7 all numbers are represented in their 2’s
complement form.
•Adding -5 and -2 results in -7, all numbers are represented in their 2’s complement form
•Now compare the addition of same numbers represented in their Signed Magnitude form. The
addition of +5 and +2 results in +7 all numbers are represented in their signed form.
•However, adding -5 and -2 results in -7. -7 is however not represented in its signed form. In fact
it represents +7.
Slide 6
0101 +5 0101 +5
1110 -2 1010 -2
10011 +3 1111 +3
1011 -5 1101 -5
0010 +2 0010 +2
1101 -3 1111 -3
Range of Numbers
Unsigned
◦ Positive Numbers Only (0 to 7)
◦ 3-bit
Signed Magnitude
◦ Positive & Negative Numbers (-7 to 7)
◦ 4-bit
2’s Complement
◦ Positive & Negative Numbers (-8 to 7)
◦ 4-bit
1099 to 10-99
Option II
Biased 50 Exponent
Counting in Hexadecimal
Decimal Binary Hexadecimal Decimal Binary Hexadecimal
0 0000 0 8 1000 8
1 0001 1 9 1001 9
2 0010 2 10 1010 A
3 0011 3 11 1011 B
4 0100 4 12 1100 C
5 0101 5 13 1101 D
6 0110 6 14 1110 E
7 0111 7 15 1111 F
Counting in Hexadecimal
Decimal Hexa- Decimal Hexa- Decimal Hexa-
Decimal Decimal Decimal
16 10 24 18 32 20
17 11 25 19 33 21
18 12 26 1A 34 22
19 13 27 1B 35 23
20 14 28 1C 36 24
21 15 29 1D 37 25
22 16 30 1E 38 26
23 17 31 1F 39 27
DR. JAVED IQBAL (SUIT PESHAWAR) JAVED.EE@SUIT.EDU.PK
Slide 14
Binary-Hexadecimal Conversion
Binary to Hexadecimal Conversion
◦ 11010110101110010110
◦ 1101 0110 1011 1001 0110
◦D 6 B 9 6
Hexadecimal to Binary Conversion
◦ FD13
◦F D 1 3 in Base 16 (H)
Decimal-Hexadecimal Conversion
Decimal-Hexadecimal Conversion
Repeated Division by 16
2096 131 0
131 8 3
8 0 8
Sum-of-Weights
CA02
= (C x 163) + (A x 162) + (0 x 161) + (2 x 160)
= (12 x 163) + (10 x 162) + (0 x 161) + (2 x 160)
= (12 x 4096) + (10 x 256) + (0 x 16) + (2 x 1)
= 49152 + 2560 + 0 + 2
= 51714
Hexadecimal Addition
Carry 1
2AC6 6+5=11d Bh
+ 92B5 C+B=23d 17h
BD7B A+2+1=13d Dh
2+9=11d Bh
Hexadecimal Subtraction
Borrow 111
92B5 21-6=15d Fh
- 2AC6 26-C=14d Eh
67EF 17-A=7d 7h
8-2=6d 6h
Counting in Octal
Decimal Binary Octal
0 000 0
1 001 1
2 010 2
3 011 3
4 100 4
5 101 5
6 110 6
7 111 7
DR. JAVED IQBAL (SUIT PESHAWAR) JAVED.EE@SUIT.EDU.PK
Slide 24
Counting in Octal
Decimal Octal Decimal Octal Decimal Octal
8 10 16 20 24 30
9 11 17 21 25 31
10 12 18 22 26 32
11 13 19 23 27 33
12 14 20 24 28 34
13 15 21 25 29 35
14 16 22 26 30 36
15 17 23 27 31 37
DR. JAVED IQBAL (SUIT PESHAWAR) JAVED.EE@SUIT.EDU.PK
Slide 25
Binary-Octal Conversion
Binary to Octal Conversion
◦11010110101110010110
◦011 010 110 101 110 010 110
◦3 2 6 5 6 2 6
Octal to Binary Conversion
◦(1726)8
◦(001 111 010 110) 2
Decimal-Octal Conversion
Decimal-Octal Conversion
Repeated Division by 8
Sum-of-Weights
4033
=(4 x 83) + (0 x 82) + (3 x 81) + (3 x 80)
=(4 x 512) + (0 x 64) + (3 x 8) + (3 x 1)
=2048 + 0 + 24 + 3
=2075
Octal Addition
Carry 1
7602 2+1=3d 3O
+ 5771 0+7=7d 7O
15573 6+7=13d 15O
1+7+5=13d 15O
Octal Subtraction
Borrow 11
7602 2-1=1d 1O
- 5771 8-7=1d 1O
1611 13-7=6d 6O
6-5=1d 1O
Alternate Representations
BCD Code
◦BCD Addition
Gray Code
Alternate Representations
•Most digital systems display a count value or the time in decimal on 7-segment LED display
panels.
•Older model Calculator had LED displays instead of the LCD displays.
•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
Slide 35
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
Gray Code
Decimal Gray Binary
0 0000 0000
1 0001 0001
2 0011 0010
3 0010 0011
4 0110 0100
5 0111 0101
6 0101 0110
7 0100 0111
DR. JAVED IQBAL (SUIT PESHAWAR) JAVED.EE@SUIT.EDU.PK
Slide 37
A A
B B
C C
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)
Punctuation and Symbols
32 Control Characters
ASCII Code
Numbers 0 to 9
ASCII 0110000 (30h) to 0111001 (39h)
Alphabets a to z
ASCII 1100001 (61h) to 1111010 (7Ah)
Alphabets A to Z
ASCII 1000001 (41h) to 1011010 (5Ah)
Control Characters
ASCII 0000000 (0h) to 0011111 (1Fh)
Alphanumeric Code
Extended ASCII 8-bit Code
Additional 128 Graphic characters
Unicode 16-bit Code
Error Detection
Digital Systems are very Reliable
Errors during storage or transmission
Parity Bit
◦Even Parity
◦Odd Parity
Summary
2’s Complement
Range and Overflow
Floating Point representation
Summary
Hexadecimal Number System
◦Binary-Hexadecimal Conversion
◦Decimal-Hexadecimal Conversion
Octal Number System
◦Binary-Octal Conversion
◦Decimal-Octal Conversion
Summary
Alternate Representations
◦BCD Code
◦Gray Code
Alphanumeric Codes
◦ASCII
Error Detection
◦Parity Bit