digital logic design mohammad fakih numbering systems
TRANSCRIPT
Digital Logic DesignMohammad Fakih
Numbering Systems
Digital Computer Systems
••
Digital systems consider discrete amounts ofdata.Examples–26 letters in the alphabet–10 decimal digits
• Larger quantities can be built from discrete values:––
Words made of letters: Football, UniversityNumbers made of decimal digits (e.g. 239875.32)
••
Computers operate on binary values (0 and1)Easy to represent binary values electrically–––
Voltages and currents.Can be implemented using circuitsCreate the building blocks of modern computers
1Digital Logic Design M.Fakih
Understanding Decimal Numbers
••
Decimal numbers are made of decimal digits: (0,1,2,3,4,5,6,7,8,9)Decimal number:– 8653 = 8x103 + 6x102 + 5x101 + 3x100
• What about fractions?––
97654.35 = 9x104 + 7x103 + 6x102 + 5x101 + 4x100 + 3x10-1 + 5x10-2
In formal notation -> (97654.35)10
• Why do we use 10 digits, anyway?
2Digital Logic Design – M.Fakih
Understanding Binary Numbers
• Binary numbers are made of binary digits (bits):– 0 and 1
• binary number:– (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
bits• a nibble.Groups of four are called– (1101) 2
3Digital Logic Design – M.Fakih
Conversion Between Number Bases
Decimal(base 10) Binary(base 2)
Hexadecimal(base16)
° Learn to convert between bases.
4Digital Logic Design – M.Fakih
Decimal review
• a weightNumbers consist of a bunch of digits, each with
1100
610
21
. 31/10
71/100
51/1000
DigitsWeights
• These weights arethis:
all powers of the base, which is 10. We can rewrite
1102
6101
2100
. 310-1
710-2
510-3
DigitsWeights
• To find the decimal value of a number, multiply each digit by its weightand sum the products.
(1 x 102) + (6 x 101) + (2 x 100) + (3 x 10-1) + (7 x 10-2) + (5 x 10-3) = 162.375
5Digital Logic Design – M.Fakih
Converting binary to decimal
• We can use the same trick to convert binary, or base 2, numbers todecimal. This time, the weights are powers of 2.– Example: 1101.01 in binary
123
122
021
120
. 02-1
12-2
Binary digits, or bitsWeights (in base 10)
– The decimal value is:
(1 x 23) + (1 x 22) + (0 x0
21) + (1+
x 20) + (0 x 2-1) + (1 x 2-2) ==8 + 4 + 1 + 0 + 0.25 13.25
6Digital Logic Design – M.Fakih
Powers of 2: Useful abbreviations:20 = 1 24 = 16 28 = 256 K = 210 = 1,02421 = 2 25 = 32 29 = 512 M = 220 = 1,048,57622 = 4 26 = 64 210 = 1024 G = 230 = 1,073,741,82423 = 8 27 = 128
Converting decimal to binary
• To convert a decimal integer into binary, keep dividing by 2 until thequotient is 0. Collect the remainders in reverse order.
• To convert a fraction, keep multiplying the fractional part by 2 until itbecomes 0. Collect the integerExample: 162.375:
parts in forward order.•
162 / 281 / 240 / 220 / 210 / 2
5 / 22 / 21 / 2
========
814020105210
remremremremremremremrem
01000101
0.3750.7500.500
xxx
222
===
0.7501.5001.000
• So, 162.37510 = 10100010.0112
7Digital Logic Design – M.Fakih
Base 16 is useful too
• The hexadecimal system uses 16 digits:0 1 2 3 4 5 6 7 8 9 A B C D E F
You can convert between base 10 and base16 using techniques like the ones we justshowed for converting between decimal andbinary.For our purposes, base 16 is most useful asa “shorthand” notation for binary numbers.
•
•
– Since 16 = 24, one hexadecimal digit isequivalent to 4 binary digits.
– It’s often easier to work withlike B4 instead of 10110100.
a number
8Digital Logic Design – M.Fakih
Decimal Binary Hex0 0000 01 0001 12 0010 23 0011 34 0100 45 0101 56 0110 67 0111 78 1000 89 1001 910 1010 A11 1011 B12 1100 C13 1101 D14 1110 E15 1111 F
Binary and hexadecimal conversions
• Converting from hexadecimal to binary is easy: just replace each hexdigit with its equivalent 4-bit binary sequence.
261.3516 ==
20010
60110
10001
.
.3
0011516
01012
• To convert from binary to hex, make groups of 4 bits, starting from thebinary point. Add 0s to the ends of the number if needed. Then, justconvert each bit group to its corresponding hex digit.
10110100.0010112 ==
1011B
01004
.
.0010
211002
C16
9Digital Logic Design – M.Fakih
Hex BinaryC 1100D 1101E 1110F 1111
Hex Binary8 10009 1001A 1010B 1011
Hex Binary4 01005 01016 01107 0111
Hex Binary0 00001 00012 00103 0011
Hex to Decimal
8163x
10Digital Logic Design – M.Fakih
7162x C
161x 9
160x
(87C9)16 = (???)10
32,768 + 1792 + 192 + 9(87C9)16 = (34,761)10
Convert Decimal to Hex
Integer Part: Divide by the base,keep track of the remainder, and read up.
1616 2,172 rem
remremrem
91278
16 = C Read up16
0
34,76110 = 87C916
11Digital Logic Design – M.Fakih
8135
34,761
Questions
100101012 = ? (decimal)
12Digital Logic Design – M.Fakih
Questions
85710 = ?16
13Digital Logic Design – M.Fakih
Questions
BED16 = ?2
14Digital Logic Design – M.Fakih
Addition
15Digital Logic Design – M.Fakih
Binary Addition
••
Binary addition is very simple.This is best shown in an example of adding two binary numbers…
1
01
1 1
1
1
11
1
10
1
11
carries
11+
---------------------1 0 1 0 1 0 0
16Digital Logic Design – M.Fakih
Binary addition example worked out
••
Some terms are given hereExercise: what are these numbers equivalent to in decimal?
The initial carryin is implicitly 0
1 111
101
011
(Carries)(Augend)(Addend)
10+
1 1 0 0 1 (Sum)
most significantbit (MSB)
least significantbit (LSB)
17Digital Logic Design – M.Fakih
Subtraction
18Digital Logic Design – M.Fakih
Binary Subtraction
° We can also perform subtraction (with borrows in place ofcarries).
° Let’s subtract (10111)2 from (1001101)2…
110
100
borrows0 10 0 10
1 0 01
10
11
01
11-
------------------------1 1 0 1 1 0
19Digital Logic Design – M.Fakih
Negative Numbers
Subtract by adding
73-3538
73+65138
10’s complement
Ignore carry
20Digital Logic Design – M.Fakih
Two’s Complement Shortcuts• Algorithm – Simply complement each bit and then add 1 to
result.the
– Finding the 2’s complement of (01100101)2complement…
and of its 2’s
N = 0110010110011010
[N] = 1001101101100100
1---------------01100101
+ 1 +---------------
10011011
21Digital Logic Design – M.Fakih
This is called one’scomplement
Negative Numbers
Subtract by
0 1 0 0 1 0 0 1
1 1 0 1 1 1 0 1
adding
7335
2’s
0100100100100011
11011100 flip
+1
-----------
11011101
0 0 1 0 0 1 1 0 comp
-35
22Digital Logic Design – M.Fakih
73-3538
Table 2.2Positive and Negative Binary Numbers
23Digital Logic Design – M.Fakih
Signed decimal Hex Binary Unsigned decimal-128-127-126
………-3-2-10123
…
…125126127
808182………FDFEFF00010203……
7D7E7F
100000001000000110000010………11111101111111101111111100000000000000010000001000000011………011111010111111001111111
128129130
………
253254255
0123
………
125126127
Signed Numbers
4-bit: 8H = -8 toto
7H = +71000 0111
8-bit: 80H = -128 to 7FH=
+127
16-bit: 8000H7FFFH
==-32,768+32,767
to
32-bit: 80000000H7FFFFFFFH
==-2,147,483,648+2,147,483,647
to
24Digital Logic Design – M.Fakih
Questions
What is the two’s00101100?
complement of
What hex number represents thedecimal number -40?
25Digital Logic Design – M.Fakih
Multiplication
26Digital Logic Design – M.Fakih
Binary Multiplication
• Binary multiplication is much the same as decimal multiplication,except that the multiplication operations are much simpler…
1 01
10
11
10X
-----------------------0001
0101
010
01
0101
001
-----------------------1 1 1 0 0 1 1 0
27Digital Logic Design – M.Fakih
ASCII CODES
28Digital Logic Design – M.Fakih
ASCII
• The most commonly used code for representing letters, numeralsand punctuation characters (alphanumeric data)
• Each character is represented with a 7-bit string; for example:‘3’ = 00110011‘ ’ = 00100000
(hex 33)(hex 20)
• An 8-bit extension of ASCII has also been defined
29Digital Logic Design – M.Fakih
ASCII Code
••
American Standard Code for Information InterchangeASCII is a 7-bit code, frequently used with an 8th bit for errordetection (more about that in a bit).
30Digital Logic Design – M.Fakih
Character ASCII (bin) ASCII (hex) Decimal
A 1000001 41 65
B 1000010 42 66
C 1000011 43 67
…
Z
a
…
1
‘
BCD
31Digital Logic Design – M.Fakih
Binary Coded Decimal
• Binary coded decimal (BCD) represents each decimal digit with four bits– Ex. 0011 0010 1001 = 329BCD
3 2 9••
This is NOT the same as 0011001010012
Why do this? Because people think in decimal.
32Digital Logic Design – M.Fakih
Digit BCD Code Digit BCD Code
0 0000 5 01011 0001 6 01102 0010 7 01113 0011 8 10004 0100 9 1001
Putting It All Together
°°
BCD not very efficient
Used in earlycomputers (40s, 50s)Used to encodenumbers for seven-segment displays.
°
° Easier to read?
33Digital Logic Design – M.Fakih
Gray code
34Digital Logic Design – M.Fakih
Gray code
35Digital Logic Design – M.Fakih
0123456789101112131415
0000000100100011010001010110011110001001101010111100110111101111
Decimal Binary Gray code
0000000100110010011001110101010011001101111111101010101110011000
Gray code is an un-weighted code that has asingle bit change betweenone code word and thenext in a sequence. Graycode is used to avoidproblems in systemswhere an error can occurif more than one bitchanges at a time.
Floatingpoint
36Digital Logic Design – M.Fakih
Express the speed of light, c, in single precision floating pointnotation. (c = 0.2998 x 109)
Floating point notation is capable of representing verylarge or small numbers by using a form of scientificnotation. A 32-bit single precision number is illustrated.
S E (8 bits) F (23 bits)
Sign bit Magnitude with MSB droppedBiased exponent (+127)
In scientific notation, c = 1.0001 1101 1110 1001 0101 1100 0000 x 228.
0 10011011 001 1101 1110 1001 0101 1100
In binary, c = 0001 0001 1101 1110 1001 0101 1100 00002.
S = 0 because the number is positive. E = 28 + 127 = 15510 = 1001 10112.F is the next 23 bits after the first 1 is dropped.In floating point notation, c =
Floating point
Digital Logic Design – M.Fakih 37