You are on page 1of 26

1110110100101010101111

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.

DECIMAL NUMBER SYSTEM

• 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.

…105 104 103 102 101 100.

• For fractional decimal numbers, the column weights are negative powers of ten that
decrease from left to right:

102 101 100. 10-1 10-2 10-3 10-4 …

• 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 :

125010 = (1x103) + (2x102) + (5x101) + (0x100)


= 1000 + 200 + 50 + 0
= 125010

73.4110 = (7x101) + (3x100) + ( 4x10-1)+(1x10-2)


= 70 + 3 + 0.4 + 0.01
= 73.4110

2
EE202-Number and Code Systems

BINARY NUMBER SYSTEM

• 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

Decimal Number Binary Number


0 0000
1 0001
2 0010
3 0011
4 0100
5 0101
6 0110
7 0111
8 1000
9 1001
10 1010
11 1011
12 1100
13 1101
14 1110
15 1111

3
EE202-Number and Code Systems

CONVERSION AMONG BASES

QUICK EXAMPLE : 2510 = 110012 = 318 = 1916

(I) BINARY TO DECIMAL CONVERSION


• Any binary number can be converted to its decimal equivalent simply by summing
together the weights of the various positions in the binary number which contain a bit 1.
• Example 1 : Convert the binary number 110112 to decimal.
Solution : Write down column weights until the last number is larger than the one you
want to convert.
110012 = (1x20)+(1x23)+(1x24)
= (1+8+16)
= 2510

• Example 2: Convert the binary number 100101.01 to decimal.

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

(II) DECIMAL TO BINARY CONVERSION


• There are 2 methods:

(I) Reverse of Binary-To-Digital Method

• Example 1 :Convert 4510 to binary

4510 = 32 + 0 + 8 + 4 + 0 + 1
= 25 + 0 + 23 + 22 + 0 + 20
= 1011012

(II) Repeat Division


• This method uses repeated division by 2.
• Technique :
• Divide by two, keep track of the remainder
• First remainder is LSB, least-significant bit
• Last remainder is bit MSB, Most Significant Bit

• Example 1 : Convert 2510 to binary

Solution :

25/2 = 12 + remainder of 1 1 (Least Significant Bit)


12/2 = 6 + remainder of 0 0
6/2 = 3 + remainder of 0 0
3/2 = 1 + remainder of 1 1
1/2 = 0 + remainder of 1 1 (Most Significant Bit)

Answer : 2510 = 110012

• A decimal fraction number can be converted to binary number by repeatedly multiplying


the fractional number by 2.The carries form the binary number.

• Example 1 : Convert 0.18810 to binary


Solution :

0.188 x 2 = 0.376 carry = 0 (Most Significant Bit)

0.376 x 2 = 0.752 carry = 0

0.752 x 2 = 1.504 carry = 1

0.504 x 2 = 1.008 carry = 1

0.008 x 2 = 0.016 carry = 0 (Least Significant Bit)

Answer = 0.00110 (for five significant digits)

5
EE202-Number and Code Systems

• Example 2 : Convert 12.812510 to binary


Solution :
12/2 = 6 + remainder of 0 0 (Least Significant Bit)
6/2 = 3 + remainder of 0 0
3/2 = 1 +remainder of 1 1
1/2 = 0 + remainder of 1 1 (Most Significant Bit)

Result : 1210 = 11002

Solution :

0.8125 x 2 = 1.625 carry 1


0.625 x 2 = 1.25 carry 1
0.25 x 2 = 0.50 carry 0
0.50 x 2 = 1.00 carry 1

Result : 0.812510 = 0.11012

Answer : 12.812510 = 1100.11012

EXERCISE

Let Do This!
Convert 24.3710 to binary.

6
EE202-Number and Code Systems

OCTAL NUMBER SYSTEM


• The octal number system has a base of eight, meaning that it has eight possible
digits : 0,1,2,3,4,5,6,7.
• Octal is also a weighted number system. The column weights are positive powers of
eight, which increase from right to left.

…84 83 82 81 80.
• For fractional octal numbers, the column weights are negative powers of eight that
decrease from left to right:

82 81 80. 8-1 8-2 8-3 8-4 …

(III) OCTAL TO BINARY CONVERSION


• Each Octal digit is represented by three binary digits.

• Technique :
• Convert each octal digit to a 3-bit equivalent binary representation

• Example 1 : Convert 358 to binary


Solution : 3 5
011 101

So, 358 = 0111012

• Example 2 : Convert 27.358 to binary


Solution : 2 7 . 3 5
010 111 . 011 101

So,27.358 = 010111.0111012

7
EE202-Number and Code Systems

EXERCISE

Convert 46.5328 to binary.

Let’s Try!

(VI) BINARY TO OCTAL CONVERSION


• Technique :
• Group bits in threes, starting on right
• Convert to octal digits

• Example 1 : Convert 1001110102 to octal


Solution : 100 111 010

4 7 2

So, 1001110102 = 4728

• Example 2 : Convert 10110101112 to octal.

Solution : 001 011 010 111

1 3 2 7

So, 10110101112 = 13278

• Example 3 : Convert 1101011.10112 to octal.

Solution : 001 101 011 . 101 100


1 5 3 . 5 4

So, 1101011.10112 = 153.548

8
EE202-Number and Code Systems

EXERCISE

Convert 010110101.0112 to octal.

Let’s Try!

(V) OCTAL TO DECIMAL CONVERSION


• Technique
– Multiply each bit by 8n, 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

• Example 1 : Convert 2378 to decimal.

Solution : 2378 = (2 x 82) + (3 x 81) + (7 x 80)

= 148 + 24 + 7

= 15910

• Example 2 : Convert 12.38 to decimal

Solution : 12.38 = 1 x (81) + 2 x (80) + 3 x (8-1)

= 8 + 2 + 0.375

= 10.37510

EXERCISE

Let Do This!
Convert 67.318 to decimal

9
EE202-Number and Code Systems

(VI) DECIMAL TO OCTAL CONVERSION

• 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

• Example 1 : Convert 17710 to octal

Solution :
177/8 = 22 remainder 1 (Least significant Bit)
22/8 = 2 remainder 6
2/8 = 0 remainder 2 (Most Significant Bit)

Result : 17710 = 2618

• A decimal fraction number can be converted to octal number by repeatedly multiplying


the fractional number by 8.

• Example 1 : Convert 172.35110 to octal


Solution :
172/8 = 21 remainder 4 (Least Significant Bit)
21/8 = 2 remainder 5
2/8 = 0 remainder 2 (Most Significant Bit)

Result : 17210 = 2548

0.351 x 8 = 2.808 carry 2


0.808 x 8 = 6.464 carry 6
0.464 x 8 = 3.712 carry 3

Result : 0.35110 = 2638

Answer : 172.35110 = 254.2638

10
EE202-Number and Code Systems

EXERCISE

Try This!
Convert 212.3410 to octal

HEXADECIMAL NUMBER SYSTEM

• The hexadecimal number system uses base 16.


• Thus, it has 16 possible digit symbols. It uses the digits 0 through 9 and the alphabetic
letters A, B, C, D, E, and F as the 16 digit symbols.
• Hexadecimal is also a weighted number system. The column weights are positive powers
of 16, which increase from right to left.

…164 163 162 161 160.


• For fractional hexadecimal numbers, the column weights are negative powers of 16 that
decrease from left to right:

162 161 160. 16-1 16-2 16-3 16-4 …

(VII) HEXADECIMAL TO BINARY CONVERSION

• Each Hexadecimal digit is represented by four binary digits.

11
EE202-Number and Code Systems

• Technique
• Convert each hexadecimal digit to a 4-bit equivalent binary representation

• Example 1 : Convert 10AF16 to binary.


Solution : 1 0 A F

0001 0000 1010 1111

Answer : 10AF16 = 00010000101011112

• Example 2 : Convert 27.3516 to binary


Solution :
2 7 . 3 5
0010 0111 . 0011 0101

Answer : 27.3516 = 00100111.001101012

EXERCISE

Let Do This!
Convert EC2.5516 to binary

(VIII) BINARY TO HEXADECIMAL CONVERSION

• Technique
• Group bits in fours, starting on right
• Convert to hexadecimal digits

• Example 1 : Express 1011001011112 in hexadecimal


Solution : 1011 0010 11112
= (1011) (0010) (1111)2
= B2F16
12
EE202-Number and Code Systems

• Example 2 : Convert 1001011.11012 to hexadecimal


Solution : 0100 1011 . 1101
4 B . D
= 4B.D16

EXERCISE

Express 0011011110.001102 in
hexadecimal.

Let Do This!

(IX) HEXADECIMAL TO DECIMAL CONVERSION

• 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

• Example 1 : Convert ABC16 to decimal


Solution : (A x 162) + (Bx161) + (Cx160)
= 2560 + 176 + 12
= 274810

• Example 2 : Convert 24.616 to decimal


Solution : (2 x 161) + (4 x 160) + (6 x 16-1)
= 32 + 4 + 0.375
= 36.37510

13
EE202-Number and Code Systems

EXERCISE

Express D2.416 in decimal.

Let Do This!

(X) DECIMAL TO HEXADECIMAL CONVERSION

• Technique
• Divide by 16
• Keep track of the remainder

• Example 1 : Convert 123410 to hexadecimal


Solution :
1234 / 16 = 77 remainder 2 (Least Significant Bit)
77 / 16 = 4 remainder D
4 / 16 = 0 remainder 4 (Most Significant Bit)

Answer : 123410 = 4D216

14
EE202-Number and Code Systems

• A decimal fraction number can be converted to hexadecimal number by repeatedly


multiplying the fractional number by 16.

• Example 2 : Convert 85.4310 to hexadecimal


Solution :

85 / 16 = 5 remainder 5 (Least Significant Bit)


5 / 16 = 0 remainder 5 (Most Significant Bit)

Result : 8510 = 5516

0.43 x 16 = 6.88 carry 6


0.88 x 16 = 14.08 carry E
0.08 x 16 = 1.28 carry 1

Result : 0.4310 = 6E116

Answer : 85.4310 = 55.6E116

EXERCISE

Convert 74.2310 to hexadecimal.

Let Do This!

15
EE202-Number and Code Systems

(XI) OCTAL TO HEXADECIMAL CONVERSION


• Technique
o Use binary as an intermediary

• Example 1 : Convert 10768 to hexadecimal


Solution :
1 0 7 6
001 000 111 110

0010 0011 1110


2 3 E

Answer : 10768 = 23E16

EXERCISE

Convert 63.158 to hexadecimal.

Let’s Try!

(XII) HEXADECIMAL TO OCTAL CONVERSION

• Technique
o Use binary as an intermediary

• Example 1 : Convert 1F0C16 to octal


Solution :
1 F 0 C
0001 1111 0000 1100

000 001 111 100 001 100


0 1 7 4 1 4

Answer : 1F0C16 = 174148

16
EE202-Number and Code Systems

EXERCISE

Convert 34.2D16 to octal.

Let Do This!

BINARY ARITHMETIC - ADDITION

• The rules for binary addition are :

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

BINARY ARITHMETIC - SUBTRACTION

• The rules for binary subtraction are :

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

00111010 (true form)


Sign Bit Magnitude Bits

• Example 1 : Find the sign-mag representation of -610


Solution :
Step1: Find binary representation using 8 bits
610 = 000001102

Step2: If the number is a negative number flip left most bit


10000110

So: -610 = 100001102 (in 8-bit sign/magnitude form)


18
EE202-Number and Code Systems

1’S COMPLEMENT REPRESENTATION

• 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

2’S COMPLEMENT REPRESENTATION

• 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)

• Example 1 : Find the two’s complement representation of –610


Solution :
Step1: Find binary representation in 8 bits
610 = 000001102
Step 2: Complement the entire positive number, and then add one

00000110 (true form)

1
11111001 (1’s complement)
+ 1 (add 1)
11111010

So: -610 = 111110102 (in 2's complement form)


19
EE202-Number and Code Systems

• Alternative method for step 2


Scan binary representation from right to left, find first one bit, from low-order (right)
end, and complement the remaining pattern to the left.

00000110
11111010 (2’s complement)

2’S COMPLEMENT ARITHMETIC

• The maximum range of 2’s complement number :


• +127 to -128 for 8-bit systems
• +32 767 to -32 768 for 16-bit systems
• When adding numbers in the 2’s complement form,simply perform a regular binary
addition to get the result.
• When subtracting numbers in the 2’s complement form,convert the number being
subtracted to a negative 2’s complement number and perform a regular binary addition
[for example, 5 – 3 = 5 + (-3) ]. The result will be a 2’s complement number and if the
result is negative,the sign bit will be 1.
• Example 1 : Add 19 + 27 using 8-bit 2’s complement arithmetic.
Solution :
1 11

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)

+25 = 0001 1001

+13 = 0000 1101

-13 = 0000 1101


= 1111 0010 (1’s complement)
+ 1
1111 0011 (2’s complement)

20
EE202-Number and Code Systems

111 11
+25 = 0001 1001
+ (-13) = 1111 0011
+12 1 0000 1100

Ignore the final carry

BINARY CODED DECIMAL (BCD) 8421 SYSTEM

• 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.

Table 1 : BCD Table

DECIMAL BCD BINARY


0 0000 0000
1 0001 0001
2 0010 0010
3 0011 0011
4 0100 0100
5 0101 0101
6 0110 0110
7 0111 0111
8 1000 1000
9 1001 1001
10 0001 0000 1010
11 0001 0001 1011
12 0001 0010 1100
13 0001 0011 1101
14 0001 0100 1110
15 0001 0101 1111

21
EE202-Number and Code Systems

• Example 1: Convert 49610 to BCD


Solution : 4 9 6
0100 1001 0110

Answer : 49610 = 0100 1001 0110BCD

• Example 2 : Convert 0110 1000 0011BCD to decimal


Solution :
0110 1000 0011
6 8 3

Answer : 0110 1000 0011BCD = 68310

• Example 3 : Convert 0110 0010 1100BCD to decimal


Solution :
0111 0010 1100
7 2 *

* 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

THE ASCII CODE

• 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.

Table 2 : ASCII Table

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

2. Convert the following decimal numbers to binary.


(a) 16610 (c) 41410
(b) 251.410 (d) 366.1210

3. Convert the following binary numbers to octal.


(a) 010111012 (c) 11101102
(b) 1101101.112 (d) 01101.0102

4. Convert the following octal numbers to binary.


(a) 778 (c) 7258
(b) 45.368 (d) 214.358

5. Convert the following octal numbers to decimal.


(a) 378 (c) 122.58
(b) 5128 (d) 613.218

6. Convert the following decimal numbers to octal.


(a) 8910 (c) 75.2410
(b) 10810 (d) 45.12510

7. Convert the following binary numbers to hexadecimal.


(a) 101110012 (c) 1100101.0012
(b) 00111012 (d) 001110.112

8.Convert the following hexadecimal numbers to binary.


(a) FA16 (c) 62.1A16
(b) D6.416 (d) E2316

9. Convert the following hexadecimal numbers to decimal.


(a) CD516 (c) 91.5516
(b) 866.116 (d) B15.7516

25
EE202-Number and Code Systems

10. Convert the following decimal numbers to hexadecimal.


(a) 6810 (c) 177.7710
(b) 18710 (d) 5142.6510

11. Convert the following BCD numbers to decimal.


(a) 10011000BCD (c) 001001011000.00110001BCD
(b) 10000001BCD (d) 100100100011.01110100BCD

12. Change 461.758 to BCD code.

13. By using ASCII code,interpret the sentences below :


Good Luck!

14. Fill up the spaces with the suitable answers.

DECIMAL BINARY OCTAL HEXADECIMAL


46
1110101
510
AD1

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

You might also like