CHAPTER 2-Number System
CHAPTER 2-Number System
1
NUMBER SYSTEMS
Number systems in digital technique:
Decimal numbers based 10
2
Decimal numbers
Based on ten digits : 0,1, 2, 3, 4, 5, 6, 7, 8, 9 .
The value of a decimal number is the sum of the digits after each digit
has been multiplied by its weight, as examples 2.1 and 2.2.
3
Examples 2.1 & 2.2
36 = (3x101) + (6x100)
= (3x10) + (6x1) = 30 + 6
Express the decimal number 789.21 as sum of the values of each digit.
Solution: The whole number digit 7 has a weight of 100 (102), the digit 8
has a weight of 10 (101), the digit 9 has a weight of 1 (100), the fractional
digit 2 has a weight of 0.1 (10-1), and the fractional digit 1 has a weight of
0.01 (10-2).
Counting in binary:
0, 1, 10, 11, 100, 101, 110, 111, 1000, , 1111.
5
Table 2-1: A Binary count zero through fifteen
6
Table 2-2: Binary Weight
7
Binary to Decimal Conversion
Adding the weights of all bits that are 1 and discarding the
weights of all bits that are 0.
10111 = (1 X 24 ) + (0 X 23 ) + (1 X 22 ) + (1 X 21 ) + (1 X 20 )
= 16 + 0 + 4 + 2 + 1 = 23
Sum-of-weight method
Binary weights
256 128 64 32 16 8 4 2 1
357 = 256 + 64 + 32 + 4 + 1 101100101
Binary weights
1024 512 256 128 64 32 16 8 4 2 1
1937 = 1024 + 512 + 256 + 128 + 16 + 1 11110010001
9
Repeated division-by-2 method
PROCEDURE:
10
Repeated division-by-2 method
11
Converting Decimal fractions to Binary
Using Sum-of-weights
Binary weights
64 32 16 8 4 2 1 .5 .25 .125 .0625
95.6875 = 64 + 16 + 8 + 4 + 2 + 1 + .5 + .125 + .0625
1011111.1011
Repeated division by 2 yields the whole number while repeated
multiplication by 2 of the fraction yields the binary fraction.
12
Repeated Multiplication by 2
Begin by multiplying decimal number by 2.
13
Repeated Multiplication by 2
MSB LSB
Example: .0 1 1
Carry
0.375 x 2 = 0.75 0
0.75 x 2 = 1.50 1
0.5 x 2 = 1.00 1
14
Binary Addition
0 + 0 = 0 Sum of 0 with a carry of 0
0 + 1 = 1 Sum of 1 with a carry of 0
1+0=1 Sum of 1 with a carry of 0
1 + 1 = 10 Sum of 0 with a carry of 1
11001
+1101
100110
15
Binary Subtraction
0-0=0
1-1=0
1-0=1
10 -1 = 1 0 -1 with a borrow of 1
1011
-111
100
16
Hexadecimal Numbers
17
Table 2-3
0 0000 0
1 0001 1
2 0010 2
3 0011 3
4 0100 4
5 0101 5
6 0110 6
7 0111 7
8 1000 8
9 1001 9
10 1010 A
11 1011 B
12 1100 C
13 1101 D
14 1110 E
15 1111 F
18
Binary to hexadecimal Conversion
Break the binary number into 4-bit groups, starting the right-most bit
and replace 4-bit group with the equivalent hexadecimal symbol.
E 9 5 6 = E956 16
6 A 3 9 B = 6A39B 16
19
Hexadecimal to binary Conversion
Reverse the process and replace each hexadecimal symbol with the
appropriate four bits as illustrated below.
Solution: (a) D A 2
(b) 4 C 8 E
20
Hexadecimal to Decimal Conversion
Method 1: First convert the hexadecimal number to binary and then convert
from binary to decimal.
Solution: (a) E 3
(b) 7 8 9
= 210 + 29 + 28 + 27 + 23 + 20 = 192910
21
Hexadecimal to Decimal Conversion
Method 2: Multiply the decimal value of each hexadecimal digit by its weight
and then take the sum of these products.
22
Decimal to Hexadecimal Conversion
Repeated division of a decimal number by 16;
- the remainders formed the equivalent hexadecimal number
The first remainder produced is the least significant digit (LSD).
Solution: Hexadecimal
remainder
126/16 = 7.875 0.875 x 16 = 14 = E
25
Octal to Decimal Conversion
Multiplying each digit by its weight and summing the products.
Solution:
(a) Weight : 82 81 80
Octal number: 1 6 7
26
Decimal to Octal Conversion
Used repeated division-by-8 method, which is similar to the method used in the
conversion of decimal numbers to binary or to hexadecimal.
Solution: Octal
remainder
228/8 = 28.5 0.5 x 8 = 4
Octal digit 0 1 2 3 4 5 6 7
Binary 000 001 010 011 100 101 110 111
Example:
Convert each of the following octal numbers to binary.
(a) 738 (b) 240 8
Solution:
(a) 7 3 (b) 2 4 0
=1110112 =101000002
28
Binary to Octal Conversion
Reverse the process of octal to binary conversion.
Start with the right-most group of 3 bits and moving from right to left,
convert each 3-bit group to equivalent octal digit.
Solution:
5 1 1 2 7
= 518 = 1278
29
Octal Addition
30
Binary Coded Decimal (BCD)
There are 2 types of binary coded:
1. Weighted Code :
- Each digit carries a weight based on its position relative.
- known as BCD each decimal digit (0-9) represent by a 4-bits
binary code.
- BCD 8421, BCD 84-2-1, & BCD addition
2. Unweighted Code :
- The bit positions in the code group do not have any specific weight
assigned to them.
- Excess-3, Gray
3. Alphanumeric codes
32
Decimal to BCD Conversion
Replace each decimal digit with the appropriate 4-bit code.
Solution: (a) 2 9
(b) 4 4 7
7 9 = 7910
9 8 1 = 98110
34
BCD Addition
Add 6 (0110) to the 4-bit sum in order to skip the six invalid states
and return the code to 8421.
If a carry results when six is added, simply add the carry to the
next 4-bit group.
35
Example: Add the following BCD numbers
(d) 1000 8
+1001 . 9 +
1 0001 17 (invalid because of carry)
. + 0110 Add 6
0001 0111 (Valid BCD number)
1 7 36
0110 0111 67
+ 0101 0011 + 53
1011 1010 (Both group are invalid >9) 120
+ 0110 +0110 Add 6 to both groups
0001 0010 0000
1 2 0
37
BCD 84-2-1 Code
The designation 84-2-1 indicates the binary weights of four bits (23, 22,-21,-20).
The weight for MSB is 8 and 1 for LSB.
The decimal to BCD 84-2-1conversion is shown in table below.
Decimal Digit 0 1 2 3 4 5 6 7 8 9
BCD 84-2-1 0000 0111 0110 0101 0100 1011 1010 1001 1000 1111
38
Decimal to BCD 84-2-1 Conversion
Replace each decimal digit with the appropriate 4-bit code.
Solution: (a) 1 9
(b) 3 2 7
9 2 = 9210
3 7 5 = 375 10
40
EXCESS-3
Excess-3 means that every decimal digit, 0 through 9, must be add with 3
and it is represented by a binary code of four bits.
The decimal to BCD conversion is shown in table below.
Decimal Digit 0 1 2 3 4 5 6 7 8 9
Excess-3 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100
Invalid number for excess-3 is 0000, 0001, 0010, 1101, 1110 & 1111.
41
Decimal to Excess-3 Conversion
Replace each decimal digit with the appropriate 4-bit code.
Solution: (a) 5 6
(b) 2 8 4
Break the binary number into 4-bit groups, starting the right-most bit
and replace 4-bit group with the equivalent excess-3 codes.
9 3 = 9310
1 0 8 = 10810
43
The GRAY code
Is unweighted and is not an arithmetic code.
There are no specific weights assigned to the bit positions.
It exhibits only a single bit change from one code word to the next in sequence.
Table 2-6 is a listing of the 4-bit Gray code for decimal 0 through 15.
1 0 0 1 1 Binary
1 1 0 1 0 Gray
0 1 1 1 Binary
0 1 0 0 Gray
45
Gray Code to Binary Conversion
Rules:
The MSB (left-most) in the binary code is same as the corresponding bit in
the Gray Code.
Add each binary code bits generated to the Gray code bit in the next
adjacent position. Discard carries.
1 1 0 1 0 Binary
0 1 1 1 Gray
0 1 0 1 Binary
46
Alphanumeric Codes
Codes that represent numbers and alphabetic characters
(letters).
The first 32 characters are nongraphic commands; used only for control purposes.
The other characters are graphic symbols include digit and alphabetic.
Table 2-7 is a listing of the ASCII code.
48
Example ASCII
Determine the binary ASCII code for the following statement;
(8 Ramadhan 1423H) ;
Solution:
Symbol Binary (ASCII) Symbol Binary (ASCII)
49
Extended ASCII Characters
Use ASCII values of 128 and above for extended character sets.
50
EBCDIC
Is the abbreviation for Extended Binary Coded Decimal Interchange Code.
51
Parity Method for Error
Detection
52
Parity Bit
Parity bit means for bit error detection.
53
Table 2-10: Parity bit for BCD number
EVEN PARITY ODD PARITY
P BCD P BCD
0 0000 1 0000
1 0001 0 0001
1 0010 0 0010
0 0011 1 0011
1 0100 0 0100
0 0101 1 0101
0 0110 1 0110
1 0111 0 0111
1 1000 0 1000
0 1001 1 1001
54
Detecting An Error
Parity bit provides for the detection of a single bit error in group.
Example:
Parity BCD
55