Digital Electronics 2
Digital Electronics 2
numerical representations
different bases (binary, octal, hexadecimal, BCD)
conversion between the different bases
Arithmetic
1
Data
Representation
• Many number systems are in use in digital
technology
2
Understanding Decimal Numbers
• Decimal numbers are made of 10 digits or
numerals or symbols: (0,1,2,3,4,5,6,7,8,9)
– Why do we use 10 digits, anyway?
– Latin word digit == finger
MSD
LSD
4 3 2 1 0 -1 -2
3 5 1 4 2 . 3 7
4
Binary Numbers
•
5
Question
6
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?
– (4536)8 = 4x83 + 5x82 + 3x81 + 6x80 = (1362)10
0 0000 8 1000
1 0001 9 1001
2 0010 B 1011
3 0011
4 0100 C 1100
5 0101 D 1101
6 0110 E 1110
7 0111 F 1111
8
Summary
• Decimal number, octal number does not lend itself
to convenient implementation in digital systems
Hexadecimal
(base16)
10
Convert an Integer from Decimal to Another Base
11
Convert an Integer from Decimal to Another Base
12
Convert a Fraction from Decimal to Another Base
0.625 x 2 = 1 + 0.25 a -1 = 1
0.250 x 2 = 0 + 0.50 a -2 = 0
0.500 x 2 = 1 + 0 a -3 = 1
13
Binary Numbers--Base
2
• Computers represent all data as “strings of
bits”, each bit being either 0 or 1
• “base” 2, with 2 digits: 0 and 1
• e.g.
(101101.10)2 = 125 + 024 + 123 + 122
+ 021 + 120 + 12-1 + 02-2
(In decimal) = 32 + 0 + 8 + 4 + 0 + 1 + ½ + 0
= (45.5)10
14
Binary Numbers--Base 2
• e.g.
(1001.011)2 = 123 + 022 + 021 + 120
+02-1 + 12-2 + 12-3
15
Binary to Decimal - Example
2 3 22 21 20 (weight)
1 0 1 1
= 1•(23)+ 0• (22)+1•(21)+1•(20)
= 1•(8)+ 0•(4)+1•(2)+1•(1)
= 8+0+2+1
= 11 Decimal
16
The Growth of Binary Numbers
n 2n n 2n
0 20=1 8 28=256
1 21=2 9 29=512
2 22=4 10 210=1024
3 23=8 11 211=2048
4 24=16 12 212=4096 Mega
5 25=32 20 220=1M Giga
6 26=64 30 230=1G Tera
7 27=128 40 240=1T
17
Convert an Integer from Decimal to Octal
0.3125 x 8 = 2 + 5 a-1 =
2
0.5000 x 8 = 4 + 0 a-2 =
4 Answer (0.3125)10 = (0.24)8
19
Binary to Octal and Hexadecimal
• Basics
• Octal:
8 = 23 every 3 binary bits convert to 1
octal
• Hex:
16 = 24 every 4 binary bits convert to 1
hexadecimal
20
Binary to Octal Conversion
Standard Binary to Octal Conversion Table
Octal 0 1 2 3 4 5 6 7
Binary 000 001 010 011 100 101 110 111
Example:
(3 2 5 0 . 7 5 3 4 )8
21
Hexadecimal to Binary Conversion
HEX BINARY HEX BINARY
0 0000 8 1000
1 0001 9 1001
2 0010 A 1010
3 0011 B 1011
4 0100 C 1100
5 0101 D 1101
6 0110 E 1110
7 0111 F 1111
Example
1D7F16 = (0001 1101 0111 1111)2
1 D 7 F
Hexa 0 1 2 3 4 5 6 7
Example:
(1110 0011 0000 1100)2 = E30C16
E 3 0 C
011101010001111010011010111
3 A 8 F 4 D 7
24
Binary Hex Conversions
Binary to Hexadecimal - Example
( 6 A 8 . F 5 C )16
25
Hex to Binary Base Conversion
Hexadecimal to Binary - Example
• Each HEX digit is made up of four binary bits
ex) Convert ABC to binary
A B C
1010 1011 1100
(ABC)16 (101010111100)2
26
Converting from Hexadecimal to Decimal
• Every hex digit position has a base value
– multiply the value at the position by the base value
8 4 D 7
(84D7)16 = 8x163+4x162+13x161+7x160
= 8x4096+4x256+13x16+7x1
= 32768+1024+208+7
= (34007)10
27
Octal
• Octal is simply “base 8” number representation
010011010111
2 3 2 7
Octal and Hex Practice
Hex (4 9 5)16
011010010101
Octal (3 2 2 5)8
28
Octal Hex
Go through Binary!
29
Binary Coded Decimal (a.k.a. 8421 code)
32
BCD
33
Binary Arithmetic
Binary arithmetic is essential in all digital computers
and in many other types of digital systems
carry
10010 10010 1111
+ 1001 + 1011 + 1
11011 11101 10000
35
Binary Subtraction
0-0=0
1-1 =1
1-0 =1
0 - 1 = 1 0-1 with a borrow -1
36
BINARY MULTIPLICATION
0 x 0 = 0
0 x 1 = 0
1 x 0 = 0
1 x 1 = 1
37
Question
38
Summar
y
• Binary numbers are made of binary digits
(bits)