Title: NUMBER SYSTEMS AND CODES
1NUMBER SYSTEMS AND CODES
2Outline
- Number systems
- Number notations
- Arithmetic
- Base conversions
- Signed number representation
- Codes
- Decimal codes
- Gray code
- Error detection code
- ASCII code
3Number 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 (, ?,
?, ?).
4Radix or Base
The radix or base of the number system denotes
the number of digits used in the system.
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
5Decimal 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
6Positional 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.
7Polynomial Notation
- A number can be explicitly represented in
polynomial notation. -
-
- where rp is a weighted position and p is the
position of a digit.
8Examples
- In binary number system
-
- In octal number system
- In hexadecimal number system
9Arithmetic
Addition In binary number system,
(101101)2 (11101)2 1111 1
101101
11101
1001010
10Addition
In octal number system,
(6254)8(5173)8 1 1
6254
5173
13447
In hexadecimal number system,
(9F1B)16 (4A36)16 1 1
9F1B
4A36
D951
11Subtraction
In binary number system,
(101101)2 -(11011)2 10 10
- 101101
- 11011
10010
12Subtraction
In octal number system,
(6254)8 -(5173)8 8
- 6254
- 5173
1061
In hexadecimal number system,
(9F1B)16 -(4A36)16 16
- 9F1B
- 4A36
54E5
13Multiplication
In binary number system,
(1101)2 ? (1001)2
? 1101
? 1001
1101
0000
0000
1101
1110101
14Division
In binary number system,
(1110111)2 ?(1001)2 1101
1001 1110111
1001
1011
1001
1011
1001
10
15Base Conversions
- Convert (100111010)2 to base 8
16Base Conversion
- Convert (100111010)2 to base 10
17Base Conversion
- Convert (100111010)2 to base 16
18Base Conversion from base 8
- Convert (372)8 to base 2
- Convert (372)8 to base 10
- Convert (372)8 to base 16
19Base Conversion from base 16
- Convert (9F2)16 to base 2
- Convert (9F2)16 to base 8
- Convert (9F2)16 to base 10
20Binomial 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.
21Convert Base 10 to Base r
- Convert (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
22Convert Base 10 to Base r
- Convert (0.275)10 to base 8
- Therefore (0.275)10 (0.21463?)8
8 ? 0.275 ? 2.200 MSD
8 ? 0.200 ? 1.600
8 ? 0.600 ? 4.800
8 ? 0.800 ? 6.400
8 ? 0.400 ? 3.200 LSD
23Convert Base 10 to Base r
- Convert (0.68475)10 to base 2
- Therefore (0.68475)10 (0.10101?)2
2 ? 0.68475 ? 1. 3695 MSD
2 ? 0.3695 ? 0.7390
2 ? 0.7390 ? 1.4780
2 ? 0.4780 ? 0.9560
2 ? 0.9560 ? 1.9120 LSD
24Signed Number Representation
- There are 3 systems to represent signed numbers
in binary number system - Signed-magnitude
- 1's complement
- 2's complement
25Signed-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.
26Signed-magnitude system
271'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 -
28Example of 1's Complement
- For example in a 4-bit system, 0101 represents 5
and -
- 1010 represents ?5
291's Complement system
302'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 -
31Example of 2's Complement
- For example in a 4-bit system, 0101 represents 5
and -
- 1011 represents ?5
322's Complement system
33Addition and Subtraction in Signed and Magnitude
34Addition and Subtraction in 1s Complement
35Addition and Subtraction in2s Complement
36Overflow Conditions
- Carry-in ? carry-out
- 0111 1000
- 5 0101 -5 1011
- 3 0011 -4 1100
- -8 1000 7 10111
- Carry-in carry-out
- 0000 1110
- 5 0101 -2 1110
- 2 0010 -6 1010
- 7 0111 -8 11000
37Addition and Subtraction inHexadecimal System
Addition
Subtraction
38Codes
- Decimal codes
- Gray code
- Error detection code
- ASCII code
39Decimal codes
Decimal Digit BCD Excess-3 2421
8421
0 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
40Gray Code
Decimal 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
41Error 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
42Error 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
43ASCII 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 -- _at_ /
- control characters -- carriage return (CR) , line
feed (LF), beep
44Assignment 1
- Page 74
- 1.1 Only AB and A?B (a), (c), (f), and (g)
- 1.2 Only AB and A?B (a), (c)
- 1.3 Only AB and A?B (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)