Ch. 1 Digital Systems - Tagged
Ch. 1 Digital Systems - Tagged
Ch. 1 Digital Systems - Tagged
Design
2
Decimal Numbers
● Decimal numbers are made of decimal digits:
● (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Base = 10
● Number = d3 x B3 + d2 x B2 + d1 x B1 + d0 x B0 = Value
3
Binary Numbers
● Binary numbers are made of binary digits (bits):
● (0, 1) Base = 2
● How many items does a binary number represent?
Weights: 8 4 2 1
● (1011)2 = 1x23 + 0x22 + 1x21 + 1x20 = (11)10
● What about fractions?
● (110.10)2 = 1x22 + 1x21 + 0x20 + 1x2-1 + 0x2-2 = (6.5)10
● Group of eight bits is called a byte: (11001001)2
● Group of four bits is called a nibble: (1101)2
● Easy to represent binary values electrically
● Voltages and currents
● Can be implemented using circuits
● Create the building blocks of modern computers
● Computers operate on binary values.
4
Octal Numbers
● Octal numbers are made of octal digits:
● (0, 1, 2, 3, 4, 5, 6, 7) Base = 8
● How many items does an octal number represent?
Weights: 512 64 8 1
● (4536)8 = 4x83 + 5x82 + 3x81 + 6x80 = (2398)10
● What about fractions?
● (465.27)8 = 4x82 + 6x81 + 5x80 + 2x8-1 + 7x8-2 = (309.359375)10
5
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) Base = 16
● How many items does a hex number represent?
Weights: 4096 256 16 1
● (3A9F)16 = 3x163 + 10x162 + 9x161 + 15x160 = (15007)10
● What about fractions?
● (2D3.5)16 = 2x162 + 13x161 + 3x160 + 5x16-1 = (723.3125)10
6
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
1
AND Gate 0
0
7
Convert an Integer from Decimal to
Another Base
8
MSB LSB
Convert a Fraction from Decimal to Another
Base
● Conversion is easy!
Determine the 4-bit value for each hex digit
● Note that there are 16 different values of four bits.
● Easier to read and write in hexadecimal
● Representations are equivalent!
10
The Growth of Binary
Numbers
11
Binary-Coded Decimal (BCD)
● Binary Coded Decimal (BCD) represents each
decimal digit with four bits
Ex. 0011 0010 1001 = 329 Digit BCD Code
10
3 2 9
0 0000
1 0001
● This is NOT the same as
2 0010
0011001010012 = 80910 3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
12
Putting It All Together
Decimal Binary Octal Hexadecimal BCD
0 0000 0 0 000
1 0001 1 1 0001
2 0010 2 2 0010
3 0011 3 3 0011
4 0100 4 4 0100
5 0101 5 5 0101
6 0110 6 6 0110
7 0111 7 7 0111
8 1000 10 8 1000
9 1001 11 9 1001
10 1010 12 A 0001 0000
11 1011 13 B 0001 0001
12 1100 14 C 0001 0010
13 1101 15 D 0001 0011
14 1110 16 E 0001 0100
15 1111 17 F 0001 0101
13
How To Represent Signed
Numbers
● Plus and minus signs are used for decimal numbers:
● 25 (or +25), −16, … etc
● In computers, everything is represented as bits
● Three types of signed binary number representations:
● signed magnitude representation
● 1’s complement representation
● 2’s complement representation
● In each case: left-most bit indicates the sign:
‘0’ for positive
‘1’ for negative
14
Signed Magnitude
Representation
● The left most bit is designated as the sign bit, the
remaining bits form the magnitude
00001100 = 1210
Sign bit Magnitude
10001100 = −1210
Sign bit Magnitude
15
One’s Complement
Representation
● The one’s complement of a binary number is done by
complementing (i.e. 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
(2n − 1) − N
● # of bits (n) has to be specified.
● Positive numbers represented as n-bit numbers.
● Negative numbers represented as 1’s complement.
17
Two’s Complement
Representation
● The two’s complement of a binary number is done by
complementing (inverting) all bits then 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
(2n−1) − N + 1
● # of bits (n) has to be specified.
● Positive numbers represented as n-bit numbers.
● Negative numbers represented as 2’s complement.
19
Two’s Complement
Representation
7 0111
4 bits 6 0110
. .
16 combinations 2 0010
1 0001
0 0000
−1 1111
−2 1110
. .
. .
−7 1001
−8 1000
20
Putting It All Together
21
Finite-Precision Number
Representation
● For an n-bit number, there are 2n different unsigned
values (combinations or codes)
(0, 1, … , 2n – 1)
● Machines that use 2’s complement arithmetic can
represent integers in the range
− 2n – 1 ≤ N ≤ 2n – 1 − 1
n is the number of bits used for representing N
Note that 2n – 1 − 1 ≡ 011...11 and − 2n – 1 ≡ 100...00
● 2’s complement code has more negative numbers
than positive
● 1’s complement code has 2 representations for
zero
22
2’s Complement Addition
● Using 2’s complement representation, adding
numbers is easy
Step 1: Add binary numbers
Step 2: Ignore the resulting carry bit
● For example: (12)10 + (1)10
0 1 1 0 0
(12)10 = +(01100)2 Add + 0 0 0 0 1
= 01100 in 5-bit 2’s comp. rep. --------------
Final 0 0 1 1 0 1
(1)10 = +(00001)2 Result
= 00001 in 5-bit 2’s comp. rep.
Ignore
23
2’s Complement
Subtraction
● Using 2’s complement representation, subtracting
numbers is also easy
Step 1: Take 2’s complement of 2nd operand
Step 2: Add binary numbers
Step 3: Ignore the resulting carry bit 0 1 1 0 0
- 0 0 0 0 1
● For example: (12)10 − (1)10
2’s comp
(12)10 = +(01100)2 0 1 1 0 0
= 01100 in 5-bit 2’s comp. rep.Add + 1 1 1 1 1
(−1)10 = −(00001)2 Final
--------------
1 0 1 0 1 1
= 11111 in 5-bit 2’s comp. rep.Result
Ignore
Carry
24
2’s Complement Subtraction
(Cont’d)
25
2’s Complement Subtraction
(Cont’d)
26
Gray Code
● Gray code is not a number Digit Binary Gray
Code
system 0 0000 0000
1 0001 0001
It is an alternate way to
2 0010 0011
represent four bit data 3 0011 0010
● Only one bit changes from one 4 0100 0110
decimal digit to the next 5 0101 0111
6 0110 0101
● Useful for reducing errors in 7 0111 0100
communication 8 1000 1100
9 1001 1101
● Can be scaled to larger 10 1010 1111
numbers 11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
27
Text: ASCII Characters
ASCII: Maps 128 characters to 7-bit code.
both printable and non-printable (ESC, DEL, …)
characters
00 http://www.asciitable.com/
nul10 dle20 sp 30 0 40 @ 50 P 60 ` 70 p
01 soh11 dc121 ! 31 1 41 A 51 Q 61 a 71 q
02 stx12 dc222 " 32 2 42 B 52 R 62 b 72 r
03 etx13 dc323 # 33 3 43 C 53 S 63 c 73 s
04 eot14 dc424 $ 34 4 44 D 54 T 64 d 74 t
05 enq15 nak25 % 35 5 45 E 55 U 65 e 75 u
06 ack16 syn26 & 36 6 46 F 56 V 66 f 76 v
07 bel17 etb27 ' 37 7 47 G 57 W 67 g 77 w
08 bs 18 can28 ( 38 8 48 H 58 X 68 h 78 x
09 ht 19 em 29 ) 39 9 49 I 59 Y 69 i 79 y
0a nl 1a sub2a * 3a : 4a J 5a Z 6a j 7a z
0b vt 1b esc2b + 3b ; 4b K 5b [ 6b k 7b {
0c np 1c fs 2c , 3c < 4c L 5c \ 6c l 7c |
0d cr 1d gs 2d - 3d = 4d M 5d ] 6d m 7d }
0e so 1e rs 2e . 3e > 4e N 5e ^ 6e n 7e ~
0f si 1f us 2f / 3f ? 4f O 5f _ 6f o 7f del
28