Professional Documents
Culture Documents
0100010001000100011111
1011010101010010100110
1001010101101000111000
1010101010010010010010
0001001010100010010100
CHP 1
0111110101010101111010
0100100100101010101000
NUMBER AND CODE SYSTEM
1001000001010101010100
1000000010011001000100
1100100100010011111010
0100100100101010101000
1001000001010111101001
0010010010101010100010
0100000101001010100010
EE202-Number and Code Systems
INTRODUCTION
Many number systems are in use in digital technology. The most common are the
decimal, binary, octal, and hexadecimal systems. The decimal system is clearly the most familiar
because it is a tool that we use every day.
• The position of each digit in a weighted number system is assigned a weight based on the
base or radix of the system.
• The radix of decimal numbers is ten, because only ten symbols are used to represent any
number that is 0,1,2,3,4,5,6,7,8 and 9.
• Decimal number examples :
o 43610
o 72.310
o 102010
• The column weights of decimal numbers are powers of ten that increase from right to left -
beginning with 100 = 1.
• For fractional decimal numbers, the column weights are negative powers of ten that
decrease from left to right:
• Decimal numbers can be expressed as the sum of the products of each digit times the
column value for that digit. Thus, the numbers 125010 and 73.410 can be expressed as :
2
EE202-Number and Code Systems
• In digital systems the information that is being processed is usually presented in binary
form.
• Binary quantities can be represented by any device that has only two operating states or
possible conditions. For example a switch is only open or closed.
• Binary has a base of two and uses the digits 0 and 1 to represent quantities.
• Binary number examples :
10102
1110.1112
111100002
• The column weights of binary numbers are positive powers of two that increase from right
to left beginning with 20 =1:
…25 24 23 22 21 20.
• For fractional binary numbers, the column weights are negative powers of two that
decrease from left to right:
22 21 20. 2-1 2-2 2-3 2-4 …
• A binary counting sequence for numbers from zero to fifteen is shown in Table 1 below.
Table 1
3
EE202-Number and Code Systems
Solution :
100101.012 = (1x20)+(1x22)+(1x25)+(1x2-2)
= (1+4+32+0.25)
= 37.2510
EXERCISE
Try This!
Convert 0011.112 to decimal
4
EE202-Number and Code Systems
4510 = 32 + 0 + 8 + 4 + 0 + 1
= 25 + 0 + 23 + 22 + 0 + 20
= 1011012
Solution :
5
EE202-Number and Code Systems
Solution :
EXERCISE
Let Do This!
Convert 24.3710 to binary.
6
EE202-Number and Code Systems
…84 83 82 81 80.
• For fractional octal numbers, the column weights are negative powers of eight that
decrease from left to right:
• Technique :
• Convert each octal digit to a 3-bit equivalent binary representation
So,27.358 = 010111.0111012
7
EE202-Number and Code Systems
EXERCISE
Let’s Try!
4 7 2
1 3 2 7
8
EE202-Number and Code Systems
EXERCISE
Let’s Try!
= 148 + 24 + 7
= 15910
= 8 + 2 + 0.375
= 10.37510
EXERCISE
Let Do This!
Convert 67.318 to decimal
9
EE202-Number and Code Systems
• Repeat Division
• This method uses repeated division by 8.
• Technique :
• Divide by eight, keep track of the remainder
• First remainder is LSB, least-significant bit
• Last remainder is bit MSB, Most Significant Bit
Solution :
177/8 = 22 remainder 1 (Least significant Bit)
22/8 = 2 remainder 6
2/8 = 0 remainder 2 (Most Significant Bit)
10
EE202-Number and Code Systems
EXERCISE
Try This!
Convert 212.3410 to octal
11
EE202-Number and Code Systems
• Technique
• Convert each hexadecimal digit to a 4-bit equivalent binary representation
EXERCISE
Let Do This!
Convert EC2.5516 to binary
• Technique
• Group bits in fours, starting on right
• Convert to hexadecimal digits
EXERCISE
Express 0011011110.001102 in
hexadecimal.
Let Do This!
• Technique
• Multiply each bit by 16n, where n is the “weight” of the bit
• The weight is the position of the bit, starting from 0 on the right
• Add the results
13
EE202-Number and Code Systems
EXERCISE
Let Do This!
• Technique
• Divide by 16
• Keep track of the remainder
14
EE202-Number and Code Systems
EXERCISE
Let Do This!
15
EE202-Number and Code Systems
EXERCISE
Let’s Try!
• Technique
o Use binary as an intermediary
16
EE202-Number and Code Systems
EXERCISE
Let Do This!
0+0 = 0
0+1 =1
1+0 =1
1+1 =0 carry 1
• Example 1 : Add the binary numbers 00111 and 10101 and show the equivalent decimal
addition.
111
Solution :
00111 7
+ 10101 21
11100 28
0-0 = 0
0 - 1 = 1 with a borrow 1
1-0 =1
1-1 =0
17
EE202-Number and Code Systems
• Example 1 : Subtract the binary number 00111 from 10101 and show the equivalent
decimal subtraction.
•
111
Solution :
10101 21
- 00111 7
01110 14
SIGNED NUMBERS
• In real life we have to represent signed numbers ( like: -12, -45, 78).
• The difference between signed and unsigned numbers is the sign.
• There are two method used to representing signed numbers in binary format.
(i) sign-magnitude representation
(ii) the 2’s-complement representation
SIGN-MAGNITUDE REPRESENTATION
• In this representation, the leftmost bit of a binary code represents the sign of the value:
» 0 for positive
» 1 for negative
the remaining bits represent the numeric value.
• To compute negative values using Sign/Magnitude (sign-mag) representation, begin
with the binary representation of the positive value, then flip the leftmost zero bit.
• For example, the positive number 58 is written using 8-bits as
• The 1’s complement of a binary number is just the inverse of the digits. To form the 1’s
complement, change all 0’s to 1’s and all 1’s to 0’s.
• For example, the 1’s complement of 11001010 is 00110101
• In digital circuits, the 1’s complement is formed by using inverters:
1 1 0 0 1 0 1 0
0 0 1 1 0 1 0 1
• The 2’s complement of a binary number is found by adding 1 to the LSB of the 1’s
complement.
• Recall that the 1’s complement of 11001010 is 00110101.
• To form the 2’s complement, add 1:
1
00110101 (1’s complement)
+ 1
00110110 (2’s complement)
1
11111001 (1’s complement)
+ 1 (add 1)
11111010
00000110
11111010 (2’s complement)
19 = 0001 0011
+ 27 = 0001 1011
4610 = 0010 1110
• Example 2 : Solve the arithmetic +2510 - 1310 by using 8-bit two’s complement method.
Solution :
+2510 + (- 1310)
20
EE202-Number and Code Systems
111 11
+25 = 0001 1001
+ (-13) = 1111 0011
+12 1 0000 1100
• The binary coded decimal system is used to represent each of the 10 decimal digits as a
4-bit binary code.
• This code is useful for outputting to displays that are always numeric (0 to 9) such as
those found in digital clocks or digital voltmeters.
• Technique : Convert each decimal digit to its 4 bit binary code.
• Table 1 below illustrates the difference between straight binary and BCD.
• BCD represents each decimal digit with a 4-bit code.
• Notice that the codes 1010 through 1111 are not used in BCD.
21
EE202-Number and Code Systems
* This conversion is impossible because 1100 is not a valid binary coded decimal.
It is not in the range 0 to 9.
22
EE202-Number and Code Systems
• Most industry has settled on an input/output (I/O) code called the American Standard
Code for Information Interchange (ASCII).
• The ASCII code uses 7 bits to represent all the alphanumeric data used in computer I/O.
• Seven bits will yield 128 different code combinations as listed in Table 2.
23
EE202-Number and Code Systems
• Example 1 : List the ASCII codes for the message “Study Smart!”
Solution :
“ - 0100010
S - 1010011
t - 1110100
u - 1110101
d - 1100100
y - 1111001
sp – 0100000
S - 1010011
m - 1101101
a - 1100001
r - 1110010
t - 1110100
! - 0100001
“ - 0100010
24
EE202-Number and Code Systems
EXERCISE
1. Convert the following binary numbers to decimal.
(a) 010010112 (c) 1011.012
(b) 001101112 (d) 01110.112
25
EE202-Number and Code Systems
15. Solve the arithmetic below by using 8-bit two’s complement method. Then change the
answer to BCD 8421 code.
(i) + 4710 + 1110
(ii) + 8510 - 5310
(iii) - 9010 - 7010
26