number systems and codes. cs 3402--digital logicnumber systems and codes2 outline number systems...
DESCRIPTION
CS Digital LogicNumber Systems and Codes3 Number Systems The decimal (real), binary, octal, hexadecimal number systems are used to represent information in digital systems. Any number system consists of a set of digits and a set of operators (+, , , ).TRANSCRIPT
NUMBER SYSTEMS AND
CODES
CS 3402--Digital Logic Number Systems and Codes 2
Outline
• Number systems– Number notations– Arithmetic– Base conversions – Signed number representation
• Codes– Decimal codes– Gray code– Error detection code– ASCII code
CS 3402--Digital Logic Number Systems and Codes 3
Number Systems
The decimal (real), binary, octal, hexadecimal number systems are used to represent information in digital systems. Any number system consists of a set of digits and a set of operators (+, , , ).
CS 3402--Digital Logic Number Systems and Codes 4
Radix or Base
Decimal (base 10) 0 1 2 3 4 5 6 7 8 9
Binary (base 2) 0 1
Octal (base 8) 0 1 2 3 4 5 6 7
Hexadecimal (base 16) 0 1 2 3 4 5 6 7 8 9 A B C D E F
The radix or base of the number system denotes the number of digits used in the system.
CS 3402--Digital Logic Number Systems and Codes 5
Decimal Binary Octal Hexadecimal
00 0000 00 0
01 0001 01 1
02 0010 02 2
03 0011 03 3
04 0100 04 4
05 0101 05 5
06 0110 06 6
07 0111 07 7
08 1000 10 8
09 1001 11 9
10 1010 12 A
11 1011 13 B
12 1100 14 C
13 1101 15 D
14 1110 16 E
15 1111 17 F
CS 3402--Digital Logic Number Systems and Codes 6
Positional Notation
It is convenient to represent a number using positional notation. A positional notation is written as a sequence of digits with a radix point separating the integer and fractional part.
where r is the radix, n is the number of digits of
the integer part, and m is the number digits of the fractional part.
rmnnr aaaaaaaN 210121 .
CS 3402--Digital Logic Number Systems and Codes 7
Polynomial Notation
A number can be explicitly represented in polynomial notation.
where rp is a weighted position and p is the
position of a digit.
mm
nn
nnr rararararararaN
22
11
00
11
22
11
CS 3402--Digital Logic Number Systems and Codes 8
Examples
In binary number system In octal number system
In hexadecimal number system
321012342 2121202021202121011.11010
3210128 848281838786124.673
101216 16166160163.306 DD
CS 3402--Digital Logic Number Systems and Codes 9
Arithmetic
(101101)2 +(11101)2 : 1111 1
+ 101101 11101
1001010
Addition:
In binary number system,
CS 3402--Digital Logic Number Systems and Codes 10
Addition
(6254)8+(5173)8 : 1 1
+ 6254 5173
13447
In octal number system,
(9F1B)16 +(4A36)16 : 1 1
+ 9F1B 4A36
D951
In hexadecimal number system,
CS 3402--Digital Logic Number Systems and Codes 11
Subtraction
(101101)2 -(11011)2 : 10 10
- 101101 11011
10010
In binary number system,
CS 3402--Digital Logic Number Systems and Codes 12
Subtraction
In octal number system,
In hexadecimal number system,
(6254)8 -(5173)8 : 8
- 6254 5173
1061
(9F1B)16 -(4A36)16 : 16
- 9F1B 4A36
54E5
CS 3402--Digital Logic Number Systems and Codes 13
Multiplication
(1101)2 (1001)2 :
1101 1001 1101 0000
00001101
1110101
In binary number system,
CS 3402--Digital Logic Number Systems and Codes 14
Division
(1110111)2 (1001)2 :
1101
1001 1110111
1001
1011 1001
1011 1001
10
In binary number system,
CS 3402--Digital Logic Number Systems and Codes 15
Base Conversions
Convert (100111010)2 to base 8
8
012
01112
0123456782
472828784
8281828484202120212121202021100111010
8
22
472274010111100100111010
CS 3402--Digital Logic Number Systems and Codes 16
Base Conversion
Convert (100111010)2 to base 10
10
1010101010
0123456782
314281632256
202120212121202021100111010
CS 3402--Digital Logic Number Systems and Codes 17
Base Conversion
Convert (100111010)2 to base 16
16
012
00112
0123456782
1316163161
162168161162161202120212121202021100111010
AA
16
22
1331101000110001100111010
AA
CS 3402--Digital Logic Number Systems and Codes 18
Base Conversion from base 8
• Convert (372)8 to base 2
• Convert (372)8 to base 10
• Convert (372)8 to base 16
2
8
11111010010111011273372
10
101010
0128
250256192828783372
16
28 10101111372FAAF
CS 3402--Digital Logic Number Systems and Codes 19
Base Conversion from base 16
• Convert (9F2)16 to base 2
• Convert (9F2)16 to base 8
• Convert (9F2)16 to base 10
2
16
1010011111000010111110012929
FF
82
16
4762)2
0106
1107
1114
100(0010111110012929
FF
10
101010
01216
254622402304 1621616929
FF
CS 3402--Digital Logic Number Systems and Codes 20
Binomial expansion (series substitution)
To convert a number in base r to base p.– Represent the number in base p in binomial
series.– Change the radix or base of each term to base p.– Simplify.
CS 3402--Digital Logic Number Systems and Codes 21
Convert Base 10 to Base rConvert (174)10 to base 8
Therefore (174)10 = (256)8
8 1 7 4 6 LSB 8 2 1 5 8 2 2 MSB 0 0
CS 3402--Digital Logic Number Systems and Codes 22
Convert Base 10 to Base rConvert (0.275)10 to base 8
Therefore (0.275)10 = (0.21463)8
8 0.275 2.200 MSD8 0.200 1.600 8 0.600 4.800 8 0.800 6.400 8 0.400 3.200 LSD
CS 3402--Digital Logic Number Systems and Codes 23
Convert Base 10 to Base rConvert (0.68475)10 to base 2
Therefore (0.68475)10 = (0.10101)2
2 0.68475 1. 3695 MSD2 0.3695 0.7390 2 0.7390 1.4780 2 0.4780 0.9560 2 0.9560 1.9120 LSD
CS 3402--Digital Logic Number Systems and Codes 24
Signed Number Representation
There are 3 systems to represent signed numbers in binary number system:– Signed-magnitude– 1's complement– 2's complement
CS 3402--Digital Logic Number Systems and Codes 25
Signed-magnitude system
In signed-magnitude systems, the most significant bit represents the number's sign, while the remaining bits represent its absolute value as an unsigned binary magnitude.– If the sign bit is a 0, the number is positive.– If the sign bit is a 1, the number is negative.
CS 3402--Digital Logic Number Systems and Codes 26
Signed-magnitude system
CS 3402--Digital Logic Number Systems and Codes 27
1's Complement system
• A 1's complement system represents the positive numbers the same way as in the signed-magnitude system. The only difference is negative number representations.
• Let be N any positive integer number and be a negative 1's complement integer of N. If the number length is n bits, then
__
N
.)12( NN n
CS 3402--Digital Logic Number Systems and Codes 28
Example of 1's Complement
For example in a 4-bit system, 0101 represents +5 and
1010 represents 5
101001011111
0101)000110000(0101000124
CS 3402--Digital Logic Number Systems and Codes 29
1's Complement system
CS 3402--Digital Logic Number Systems and Codes 30
2's Complement system
• A 2's complement system is similar to 1's complement system, except that there is only one representation for zero.
• Let be N any positive integer number and be a negative 2's complement integer of
N. If the number length is n bits, then
__
N
.2 NN n
CS 3402--Digital Logic Number Systems and Codes 31
Example of 2's Complement
For example in a 4-bit system, 0101 represents +5 and
1011 represents 5
1011010110000010124
CS 3402--Digital Logic Number Systems and Codes 32
2's Complement system
CS 3402--Digital Logic Number Systems and Codes 33
Addition and Subtraction in Signed and Magnitude
(a) 5+2
0101+0010
7 0111
(b) -5-2
1101+1010
-7 1111
(c) 5-2
0101+1010
3 0011
(d) -5+2
1101+0010
-3 1011
CS 3402--Digital Logic Number Systems and Codes 34
Addition and Subtraction in 1’s Complement
(a) 5+2
0101+0010
7 0111
(b) -5-2
1010 +1101
-7 1 0111 1 1000
(c) 5-2
0101 +1101
3 1 0010 1 0011
(d) -5+2
1010 +0010
-3 1100
CS 3402--Digital Logic Number Systems and Codes 35
Addition and Subtraction in2’s Complement
(a) 5+2
0101+0010
7 0111
(b) -5-2
1011 +1110
-7 1 1001
(c) 5-2
0101 +1110
3 1 0011
(d) -5+2
1011 +0010
-3 1101
CS 3402--Digital Logic Number Systems and Codes 36
Overflow Conditions
Carry-in carry-out 0111 1000 5 0101 -5 1011 +3 +0011 -4 +1100 -8 1000 7 10111Carry-in = carry-out 0000 1110 +5 0101 -2 1110 +2 +0010 -6 +1010 7 0111 -8 11000
CS 3402--Digital Logic Number Systems and Codes 37
Addition and Subtraction inHexadecimal System
(9F1B)16 -(4A36)16 : 16 9F1B- 4A36 54E5
(9F1B)16 +(4A36)16 : 1 1 9F1B + 4A36
E951
Addition
Subtraction
CS 3402--Digital Logic Number Systems and Codes 38
Codes
• Decimal codes• Gray code• Error detection code• ASCII code
CS 3402--Digital Logic Number Systems and Codes 39
Decimal codesDecimal Digit BCD Excess-3 2421
84210 0000 0011 0000
1 0001 0100 0001
2 0010 0101 0010
3 0011 0110 0011
4 0100 0111 0100
5 0101 1000 1011
6 0110 1001 1100
7 0111 1010 1101
8 1000 1011 1110
9 1001 1100 1111
CS 3402--Digital Logic Number Systems and Codes 40
Gray CodeDecimal Equivalent Binary Code Gray Code
0 0000 0000
1 0001 0001
2 0010 0011
3 0011 0010
4 0100 0110
5 0101 0111
6 0110 0101
7 0111 0100
8 1000 1100
9 1001 1101
10 1010 1111
11 1011 1110
12 1100 1010
13 1101 1011
14 1110 1001
15 1111 1000
CS 3402--Digital Logic Number Systems and Codes 41
Error detection code Parity Bit (odd) Message
1 0000
0 0001
0 0010
1 0011
0 0100
1 0101
1 0110
0 0111
0 1000
1 1001
1 1010
0 1011
1 1100
0 1101
0 1110
1 1111
CS 3402--Digital Logic Number Systems and Codes 42
Error detection code Parity Bit (even) Message
0 0000
1 0001
1 0010
0 0011
1 0100
0 0101
0 0110
1 0111
1 1000
0 1001
0 1010
1 1011
0 1100
1 1101
1 1110
0 1111
CS 3402--Digital Logic Number Systems and Codes 43
ASCII Code
• ASCII: American Standard Code for Information Interchange.
• Used to represent characters and textual information• Each character is represented with 1 byte
– upper and lower case letters: a..z and A..Z– decimal digits -- 0,1,…,9– punctuation characters -- ; , . : – special characters --$ & @ / { – control characters -- carriage return (CR) , line feed (LF),
beep
CS 3402--Digital Logic Number Systems and Codes 44
Assignment 1
Page 74– 1.1: Only A+B and AB (a), (c), (f), and (g)– 1.2: Only A+B and AB (a), (c)– 1.3: Only A+B and AB (a), (c)– 1.4: (a), (c), (e)– 1.5: (a), (c), (e)– 1.6: (a), (e)– 1.7: (a), (b)– 1.8: (a), (b)– 1.10: (a), (c)– 1.11: (a), (c)– 1.12: (a), (c)– 1.13: (a), (b)