Lecture1, 2, 3-Digital Systems I - Topic 1, Number Systems
Lecture1, 2, 3-Digital Systems I - Topic 1, Number Systems
Z. Navabi
Topic 1
Number Systems
Zain Navabi
2
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Why Binary?
• Computers don’t understand words or numbers the way humans do.
Decimal Point
Binary Point
3 2 1 -1 -2 -3 -4
−𝟒
4𝟒
𝟏𝟎
2 𝟏𝟎
2
𝟑 𝟏𝟎
2
𝟐 𝟏𝟎
2
𝟏 𝟏𝟎
2
𝟎
0
𝟏𝟎−𝟏
2 𝟏𝟎−𝟐
2 𝟏𝟎−𝟑
2 2𝟏𝟎
2 5 . 1 3
25.13= 2*101 +5*100 + 1*10-1+3*10-2
Integer Fraction
4
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Decimal and Binary
Binary Numbers
Binary Point
4 3 2 1 0 -1 -2 -3 -4
2 2 2 2 2 2 2 2 2
1 1 0 0 1 . 0 0 1 0
(11001.1010)2 = 1*24 + 1*23 +0*22 + 0*21 +1*20 + 0*2-1+0*2-2+ 1*2-3+0*2-4 = (25.125)10
Integer Fraction
5
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Decimal and Binary
Decimal to Binary Conversion (Integer Part)
(29.61)10=(?)2
Multiple divisions and collecting the remainders, the first remainder is the nearest
digit to the binary point.
14 07 03 1
2 29 2 14 2 07 2 03
28 14 06 02
1 0 1 1
(29)D = (11101.)B
Binary point
6
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Decimal and Binary
Decimal to Binary Conversion (Fractional Part)
Use multiplication to find the fractional part.
0.61*2 = 1 . 22
0.22*2 = 0 . 44
0.44*2 = 0 . 88 (0.61)10=(.100111)2 (29.61)10=(11101.100111)2
0.88*2 = 1 . 96
0.96*2 = 1 . 92
0.92*2 = 1 . 84
7
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Octal and Hex 0000 0
0001 1
To do conversions from base 2 to base 8(16), each 3(4) bits in 0010 2
base 2 must be converted into it’s equivalent in base 8(16).
0011 3
0100 4
(35.37)10 = (00 100 011.010 111 00)2 0101 5
0110 6
(35.37)10 = (43.27)octal 0111 7
(35.37)10 = (0010 0011.0101 1100)2 1000 8
1001 9
(35.37)10 = (23.5C)Hex 1010 A
1011 B
1100 C
1101 D
1110 E
1111 F
8
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Coding System
1- Signed Numbers
• We define the left-most digit as the number’s sign digit.
• The definition constructs the Sign and Magnitude representation of numbers.
• In this representation all digits except the left-most construct the magnitude of
the number, while the left-most digit being 1 shows that the number is negative
or positive otherwise.
Sign Magnitude
0 1001001 +73
1 1001001 -73
9
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Coding System
2- Binary Coded Decimal
• A system of writing numerals.
• Assigns a four-digit binary code to each digit 0 through 9 in a decimal (base-10) numeral.
0000 0
0001 1
0010 2
0011 3
0100 4
0101 5
0110 6
0111 7
1000 8
1001 9
10
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Coding System
3- Seven Segment Display Code
• A system for simple display of digits 0 to 9.
• Assigns a seven-digit binary code to each digit 0 through 9 (base-10) numeral.
a b c d e f g
0 0000 1 1 1 1 1 1 0
1 0001 0 1 1 0 0 0 0
2 0010 1 1 0 1 1 0 1
3 0011 1 1 1 1 0 0 1
4 0100 0 1 1 0 0 1 1
5 0101 1 0 1 1 0 1 1
6 0110 1 0 1 1 1 1 1
7 0111 1 1 1 0 0 0 0
8 1000 1 1 1 1 1 1 1
9 1001 1 1 1 1 0 1 1
11
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Coding System
3- Seven Segment Display Code
12
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Coding System Decimal Binary
0 0000
Gray
0000
4- Gray Code 1 0001 0001
• Physical switches are not ideal: it is very unlikely that physical switches 2 0010 0011
will change states exactly in synchrony. 3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
0111 1111 1101 1001 0100
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
• Solution: Two successive values differ in only one bit.
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
13
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Coding System
5- ASCII
• In some application storing text is the
most important of all. The ASCII
code is used for this mean.
14
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Coding System
5- ASCII
• 8-bit codes are used to represent the ASCII codes, where the leftmost digit
specifies which table a specific code belongs to. Codes starting with 1 are
from the extended ASCII table and those starting with 0 belongs to the
basic one.
• Special characters are also included in the ASCII code range. It’s also true
about the control characters.
15
Introduction to Digital System Design - Copyright Zainalabedin Navabi
Binary arithmetic
1- Addition
• Adding numbers in base 2 can be considered the same as decimal
Addition.
• The main problems can occur when doing subtractions. But even
in this case the borrowing is just as it is in decimal numbers.
+2 +2 +2 +2
+1 +1 +1 1 01101
101101 +1 +1 +1 +1
+ 011001 - 0 01110
1000110 0 11111
Addition Subtraction
• The same rule as the sign and magnitude representation for distinguishing
positive numbers from negative ones applies in the 2’s complement
system.
• In the 2’s complement system, the positive numbers have the same form
as they have in the sign and magnitude system.
+1 +1 +1 +1
0 0 0 1 1 0 1 1 negating 0 0 0 1 1 0 1 1
- 01001101 + 10110011
11001110 -(00110010)
Binary
Subtraction
Introduction to Digital System Design - Copyright Zainalabedin Navabi 20
Binary arithmetic
5- Overflow
0 0 1 1 0 1 0 0
+
0 1 1 0 1 0 0 0
1 0 0 1 1 1 0 0
• The result could have been shown correctly in 9 bits, but our system has at most 8.
0 0 0 0 0 0 0 0 0 0 1 1 0 1 0 0
+
0 0 0 0 0 0 0 0 0 1 1 0 1 0 0 0
0 0 0 0 0 0 0 0 1 0 0 1 1 1 0 0
Sign-Extension