Chapter 1
Chapter 1
Chapter 1
Number systems
Number Systems
Number representations
Computations
Common codes
Part 1
Number representations
Number representations
1. Decimal system
2. Binary system
3. Hexadecimal system
4. Octal system
Number representations
1. Decimal system
Symbol: D
Base: 10
Digits used: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
Example:
11.25D
19D
Number representations
2. Binary system
Symbol: B
Base: 2
Digits used: 0, 1.
Example:
101011B
1011.01B
Number representations
Example:
Convert the following binary numbers into decimal
system.
a/ 1010.1101B
b/ 1001.0011B
Ans. a/ 10.8125D
b/ 9.1875D
Number representations
Convert the number in decimal system into binary system
For an integer: divide the integer by 2 until the quotient
is zero. Then, collect the remainders upward
Example:
Convert 19D into B
19D = 10011B
Number representations
Example:
Convert the following decimal numbers into
binary system.
a/ 15D
b/ 23D
Ans. a/ 1111B
b/ 10111B
Number representations
Example:
Convert the following decimal numbers
into binary system.
a/ 16.75D
b/ 25.57D
Ans. a/ 10000.11B
b/ 11001.10010 B
Number representations
3. Hexadecimal system
Symbol: H
Base: 16
Digits used: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9,
A, B, C, D, E, F
The digits A, B, C, D, E, F are worth 10, 11, 12, 13, 14, 15,
respectively.
Number representations
4. Octal system
Symbol: O
Base: 8
Digits used: 0, 1, 2, 3, 4, 5, 6, 7.
Number representations
Example:
Complement 1 of 1100110B is 0011001B
Computations
2. Base Complement:
Given number N consisting of n digits in the base system r,
Base complement of N is defined:
rn - N if N ≠ 0
0 if N = 0
Example:
Complement 10 of 123D is: 103- 123 = 1000 - 123 = 877D
Complement 2 of 1100B is: 24 - 12 = 16 - 12 = 4 = 0100B
Complement 16 of 2CH is: 162 - 44 = 256 - 44 = 212 = D4H
Computations
Base complement can be calculated by adding 1 in the
complement of “base -1”
Example:
Complement 9 of 456D is 543D
Complement 10 of 456D is 543 + 1 = 544D
Complement 1 of 1011B is 0100B
Complement 2 of 1011B is 0100B + 1 = 0101B
Complement 1 of 1000B is 0111B
Complement 2 of 1000B is 0111B + 1 = 1000B
Computations in binary code
systems
range of 0 to 2n - 1.
Computations in binary code
systems
1’s complement:
first “1”
flip remaining bits to the left
Signed binary number
Example:
1. Convert -14D into signed binary number.
+14D = 01110B
Complement 2 of 01110B is 10010B
-14D = 10010B
If M <N, the sum does not produce the last carry and
equals to rn - (N-M).
This is complement r of (N-M).
To obtained the result, find complement r of the sum
and put the sign “-” in front of it.
Computations
Example:
Using complement 10 to do the subtraction: 67543 - 2465
67543
+
Complement 10 of 02465 is: 9 7 5 3 5
16 5 0 7 8
Ignore the last carry: 65078 67543 - 2465 = 65078
Computations
Example:
Using complement 10 to do the subtraction 2465 - 67543
02465
+
Complement 10 of 67543 is: 3 2 4 5 7
34922
There is no last carry. Complement 10 of 34922 is 65078.
2465 - 67543 = -65078
Computations
Example:
Using complement 2 to do the subtraction 111001 - 1010
111001
+
Complement 2 of 001010 is: 110110
11 01111
Ignore the last carry:
111001 - 1010 = 101111
Computations
Example:
Using complement 2 to do subtraction 1010 - 111001
001010
+
Complement 2 of 111001 is: 0 0 0 1 1 1
010001
There is no last carry. Find complement 2 of 010001
is 101111 1010 - 111001 = -101111
Part 3
Common Codes
Common Codes
Common Codes
Binary Coded Decimal (BCD 8421)
Used to represent the decimal digits 0 - 9.
4 bits are used.
Each bit position has a weight associated with it (weighted code).
Weights are: 8, 4, 2, and 1 from MSB to LSB (called 8-4-2-1 code).
BCD Codes:
0: 0000 1: 0001 2: 0010 3: 0011 4: 010
5: 0101 6: 0110 7: 0111 8: 1000 9: 1001
Used to encode numbers for output to numerical displays
Used in processors that perform decimal arithmetic.
Example: (9750)10 = (1001011101010000)BCD
Common Codes
2. Binary-Coded Decimal 2421( BCD 2421)
is one kind of BCD code
used to represent a decimal number
is a 4-bit binary combination with weights 2-4-2-1.
characterized by base complement
Example:
3. Excess 3 Code
Example:
Gray code 1 0 1 1 1
Gray code 1 0 0 1 1
Binary code 1 1 1 0 1
Common Codes
Gray code Table (4 bits)
Decimal Binary Gray
0 0000 0000
1 0001 0001 Two consecutive code
2 0010 0011 words differ in only 1 bit
3 0011 0010 (the distance between the
4 0100 0110 two code words is 1).
5 0101 0111
6 0110 0101
7 0111 0100
Common Codes
Gray code Table (4 bits)
Decimal Binary Gray
8 1000 1100
9 1001 1101 Two consecutive code
10 1010 1111 words differ in only 1 bit
11 1011 1110 (the distance between the
12 1100 1010 two code words is 1).
13 1101 1011
14 1110 1001
15 1111 1000