Digital Engineering
Introduction
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
10/10/2022 Digital Engineering 2
Understanding Decimal Numbers
● Decimal numbers are made of decimal digits:
(0,1,2,3,4,5,6,7,8,9) Base = 10
● But how many items does a decimal number
represent?
● 8653 = 8 x103 + 6 x102 + 5 x101 + 3 x100
● Number = d3 x B3 + d2 x B2 + d1 x B1 + d0 x B0 = Value
● What about fractions?
● 97654.35 = 9x104 + 7x103 + 6x102 + 5x101 + 4x100 + 3x10-1 + 5x10-2
● In formal notation → (97654.35)10
10/10/2022 Digital Engineering 3
Understanding Binary Numbers
● Binary numbers are made of binary digits (bits):
● 0 and 1
● How many items does a binary number represent?
● 8 4 2 1 = Weights
● (1011)2 = 1x23 + 0x22 + 1x21 + 1x20 = (11)10
● What about fractions?
● (110.10)2 = 1x22 + 1x21 + 0x20 + 1x2-1 + 0x2-2
● Groups of eight bits are called a byte
● (11001001)2
● Groups of four bits are called a nibble
● (1101)2
10/10/2022 Digital Engineering 4
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?
● 512 64 8 1 = Weights
● (4536)8 = 4x83 + 5x82 + 3x81 + 6x80 = (2398)10
● What about fractions?
● (465.27)8 = 4x82 + 6x81 + 5x80 + 2x8-1 + 7x8-2
● Octal numbers don’t use digits 8 or 9
10/10/2022 Digital Engineering 5
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 a hex number represent?
4096 256 16 1 = Weights
3 2 1 0
● (3A9F)16 = 3x16 + 10x16 + 9x16 + 15x16 = 1500710
● What about fractions?
● (2D3.5)16 = 2x162 + 13x161 + 3x160 + 5x16-1 = 723.312510
● Note that each hexadecimal digit can be
represented with four bits
● (1110)2 = (E)16
10/10/2022 Digital Engineering 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
10/10/2022 Digital Engineering 7
Convert an Integer from Decimal to Another Base
For each digit position:
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
Example for (13)10:
Quotient Remainder Coefficient
13/2 = 6 , 1 a0 = 1
6/2 = 3 , 0 a1 = 0
3/2 = 1 , 1 a2 = 1
1/2 = 0 , 1 a3 = 1
Answer (13)10 = (a3 a2 a1 a0)2 = (1101)2
MSB LSB
10/10/2022 Digital Engineering 8
Convert a Fraction from Decimal to Another Base
For each digit position:
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
Example for (0.625)10:
Integer Fraction Coefficient
0.625 x 2 = 1 + 0.250 a-1 = 1
0.250 x 2 = 0 + 0.500 a-2 = 0
0.500 x 2 = 1 + 0 a-3 = 1
Answer (0.625)10 = (0.a-1 a-2 a-3 )2 = (0.101)2
MSB LSB
10/10/2022 Digital Engineering 9
Conversion Between Base 16 and Base 2
● 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!
3A9F16 = 0011 1010 1001 11112
3 A 9 F
10/10/2022 Digital Engineering 10
The Growth of Binary Numbers
10/10/2022 Digital Engineering 11
Understanding Binary Coded Decimal
● Binary Coded Decimal (BCD) represents each
decimal digit with four bits
Ex. 0011 0010 1001 = 32910
3 2 9 Digit BCD Code
● This is NOT the same as 0 0000
0011001010012 = 80910 1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10/10/2022 Digital Engineering 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
10/10/2022 Digital Engineering 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
●1’s complement
●2’s complement
●In each case: left-most bit indicates the sign:
‘0’ for positive and ‘1’ for negative
10/10/2022 Digital Engineering 14
Signed Magnitude Representation
● The left most bit is designated as the sign bit while
the remaining bits form the magnitude
000011002 = 1210
Sign bit Magnitude
100011002 = −1210
Sign bit Magnitude
10/10/2022 Digital Engineering 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 a n-bit number N the 1’s complement is
(2n − 1) − N
● Called “diminished radix complement” by Mano
● To find the negative of a 1’s complement number
take its 1’s complement
000011002 = 1210 111100112 = −1210
Sign bit Magnitude Sign bit Code
10/10/2022 Digital Engineering 16
One’s Complement Representation
7 0111
4 bits 6 0110
. .
16 combinations . .
1 0001
0 0000
−0 1111
−1 1110
. .
. .
−6 1001
−7 1000
10/10/2022 Digital Engineering 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
● Called “radix complement” by Mano
● To find the negative of a 2’s complement number
take its 2’s complement
000011002 = 1210 111101002 = −1210
Sign bit Magnitude Sign bit Code
10/10/2022 Digital Engineering 18
Two’s Complement Shortcuts
● Algorithm 1: Complement each bit then add 1 to the
result
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, then complement the remaining bits
N =01100110
[N] =10011010
10/10/2022 Digital Engineering 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
10/10/2022 Digital Engineering 20
Putting All Together
10/10/2022 Digital Engineering 21
Finite-Precision Number Representation
● 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
n-1
Note that 2 − 1 = (011..11)2 and − 2n-1 = (100..00)2
● 2’s complement code has more negative numbers
than positive
● 1’s complement code has 2 representations for
zero
● For an n-bit number in base (i.e. radix) z there are zn
different unsigned values (combinations)
(0, 1, …zn-1)
10/10/2022 Digital Engineering 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 = +(1100)2 Add + 0 0 0 0 1
= 011002 in 2’s comp. --------------
Final 0 0 1 1 0 1
(1)10 = +(0001)2 Result
= 000012 in 2’s comp.
Ignore
10/10/2022 Digital Engineering 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
● For example: (12) − (1) - 0 0 0 0 1
10 10
(12)10 = +(1100)2 2’s comp
0 1 1 0 0
= 011002 in 2’s comp. Add + 1 1 1 1 1
(−1)10 = −(0001)2 Final
--------------
= 111112 in 2’s comp. Result 1 0 1 0 1 1
Ignore
Carry
10/10/2022 Digital Engineering 24
2’s Complement Subtraction (Cont’d)
● Example 2: (13)10 − (5)10
(13)10 = +(1101)2 = (01101)2
(−5)10 = −(0101)2 = (11011)2
● Adding these two 5-bit codes:
01101
+ 11011
Carry 1 01000
● Discarding the carry bit, the sign bit is seen to be
zero, indicating a positive result
Indeed: (01000)2 = +(8)10
10/10/2022 Digital Engineering 25
2’s Complement Subtraction (Cont’d)
● Example 3: (5)10 − (12)10
(5)10 = +(0101)2 = (00101)2
(−12)10 = −(1100)2 = (10100)2
● Adding these two 5-bit codes:
00101
+ 10100
Carry 0 11001
● 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
10/10/2022 Digital Engineering 26
Gray Code
Gray
● Gray code is not a number Digit Binary 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
5 0101 0111
decimal digit to the next
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
10/10/2022 Digital Engineering 27
Text: ASCII Characters
ASCII: Maps 128 characters to 7-bit code.
both printable and non-printable (ESC, DEL, …) characters
http://www.asciitable.com/
00 nul 10 dle 20 sp 30 0 40 @ 50 P 60 ` 70 p
01 soh 11 dc1 21 ! 31 1 41 A 51 Q 61 a 71 q
02 stx 12 dc2 22 " 32 2 42 B 52 R 62 b 72 r
03 etx 13 dc3 23 # 33 3 43 C 53 S 63 c 73 s
04 eot 14 dc4 24 $ 34 4 44 D 54 T 64 d 74 t
05 enq 15 nak 25 % 35 5 45 E 55 U 65 e 75 u
06 ack 16 syn 26 & 36 6 46 F 56 V 66 f 76 v
07 bel 17 etb 27 ' 37 7 47 G 57 W 67 g 77 w
08 bs 18 can 28 ( 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 sub 2a * 3a : 4a J 5a Z 6a j 7a z
0b vt 1b esc 2b + 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
10/10/2022 Digital Engineering 28