Sei sulla pagina 1di 30

Number Systems and Conversions

Abu Ahmed Ferdaus Assistant Professor Department of Computer Science & Engineering Dhaka University

Number Systems and Conversions


Topics: Overview of number systems Conversions: 1. Decimal to Binary 2. Decimal to Octal 3. Decimal to Hexadecimal 4. Binary to Decimal 5. Binary to Octal 6. Binary to Hexadecimal 7. Octal to Decimal 8. Octal to Binary 9. Octal to Hexadecimal 10. Hexadecimal to Decimal 11. Hexadecimal to Binary 12. Hexadecimal to Octal Exercises

Overview of Number System

1. 2.

3.
4.

Many number systems are in use in digital technology. The most common are: Decimal number system base 10 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Binary number system base 2 (0, 1) Octal number system base 8 (0, 1, 2, 3, 4, 5, 6, 7) Hexadecimal number system base 16 (0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F) The decimal system is clearly the most familiar to us because it is a tool that we use every day.

Decimal System
The decimal system is composed of 10 numerals or symbols. These 10 symbols are 0, 1, 2, 3, 4, 5, 6, 7, 8, 9; using these symbols as digits of a number, we can express any quantity. The decimal system, also called the base-10 system because it has 10 digits.

103 =1000 Most Significant Digit

102

101 100

10-1 10-2

10-3 Least Significant Digit

=100 =10 =1 . Decimal point

=0.1 =0.01 =0.001

Decimal Numbers

decimal means that we have ten digits to use in our


representation (the symbols 0 through 9)
Decimal number 3,546?

it is three thousands plus five hundreds plus four tens plus six ones.

Decimal number: 329

329
102 101 100
3x100 + 2x10 + 9x1 = 329

Binary System
In the binary system, there are only two symbols or possible digit values, 0 and 1. This base-2 system can be used to represent any quantity that can be represented in decimal or other number system.

23 =8 Most Significant Bit

22 21 20 =4 =2 =1 . Binary point

2-1

2-2

2-3 Least Significant Bit

=1/2 =1/4 =1/8

Binary Numbers

Binary (base two) system: has two states: 0 and 1 Basic unit of information is the binary digit, or bit. Binary number 101

most significant

101
22 21

least significant

20

1x4 + 0x2 + 1x1 = 5

Fractional Values

In Decimal

0.329
10-1 10-2 10-3
3x0.1 + 2x0.01 + 9x0.001 = 0.329

In Binary

0.011
2-1 2-2 2-3
0x0.5 + 1x0.25 + 1x0.125 = 0.375

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.

83 =512 Most Significant Digit

82

81 80

8-1

8-2

8-3 Least Significant Digit

=64 =8 =1 . Octal point

=1/8 =1/64 =1/512

Octal Numbers

Octal means that we have eight digits to use in our


representation (the symbols 0 through 7) Octal number 327 = ?

327
82 81 80
3x64 + 2x8 + 7x1 = 215

Hexadecimal Number System


The hexadecimal system uses base 16. Thus, it has 16 possible digit symbols. It uses the digits 0 through 9 plus the letters A, B, C, D, E, and F as the 16 digit symbols.

163 =4096 Most Significant Digit

162

161 160

16-1

16-2

16-3 Least Significant Digit

=256 =16 =1 . Hexadec. point

=1/16 =1/256 =1/4096

Hexadecimal Numbers

Hexadecimal means that we have sixteen digits to


use in our representation (the symbols 0 to 9 and A,B,C,D,E,F) Hex number 27B = ?

27B
162 161 160
2x256 + 7x16 + 11x1 = 635

Comparison of Four Number Systems


Binary 0000 0001 0010 0011 0100 0101 0110 0111 1000 1001 1010 1011 1100 1101 1110 1111 Base-2 Octal 0 1 2 3 4 5 6 7 10 11 12 13 14 15 16 17 Base-8 Decimal 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 Base-10 Hexadecimal 0 1 2 3 4 5 6 7 8 9 A B C D E F Base-16

Number Conversion
Number Conversion can be viewed as:

Binary

Decimal

Octal

Hexadecimal

1. Decimal to Binary Conversion

Repeated Division: repeatedly divide the decimal number by 2, the base of the binary system. Division by 2 will either give a remainder of 1 (dividing an odd number) or no remainder (dividing an even number). Collecting the remainders from the repeated divisions will give the binary answer. Example: convert 2510 to binary.
25/ 2 = 12+ remainder of 1 1 (Least Significant Bit)

12/ 2
6/2 3/2 1/2 Result

= 6 + remainder of 0
= 3 + remainder of 0 = 1 + remainder of 1 = 0 + remainder of 1 2510 =

0
0 1 1 (Most Significant Bit) 1 1 0 0 12

1. Decimal to Binary Conversion (Cont.)

Reading from bottom to top, the final answer is 11001. Remember that the first division gives us the least significant digit of our answer, and the final division gives us the most significant digit of our answer. Also, the result of the final division is always 0. Converting Fraction: When converting a fractional decimal value to binary, we need to use a slightly different approach. Instead of dividing by 2, we repeatedly multiply the decimal fraction by 2. If the result is greater than or equal to 1, we add a 1 to our answer. If the result is less than 1, we add a 0 to our answer. The 0 fractional parts indicates the end of the multiplication.

1. Decimal to Binary Conversion (Cont.)

Convert 0.37510 to binary. Result 0 (Leftmost digit) 1 1 (Rightmost digit)

0.375 * 2 = 0.75 0.75 * 2 = 1.5 0.5 * 2 = 1.0

So, 0.37510 = 0.0112

So, a decimal number with fraction can be converted to binary using the above methods. 25.37510 = 25 + 0.375 = 11001.0112

2. Decimal to Octal Conversion

Repeated Division: repeatedly divide the decimal number by 8, the base of the octal system. Division by 8 will give a remainder of 0..7. Also, the result of the final division is always 0. Collecting the remainders from the repeated divisions will give the octal number. Example: convert 17710 to octal and binary:

177/8 = 22+ remainder of 1 1 (Least Significant Bit) 22/ 8 = 2 + remainder of 6 6 2 / 8 = 0 + remainder of 2 2 (Most Significant Bit) Result 17710 = 2618 Convert to Binary = 0101100012

3. Decimal to Hexadecimal Conversion

Repeated Division: repeatedly divide the decimal number by 16, the base of the hexadecimal system. Division by 16 will give a remainder of 0..F(15). Also, the result of the final division is always 0. Collecting the remainders from the repeated divisions will give the hexadecimal number. Example: convert 37810 to hexadecimal and binary:
378/16 = 23+ remainder of 10 23/ 16 = 1 + remainder of 7 1 / 16 = 0 + remainder of 1 Result 37810 = Convert to Binary A (Least Significant Bit) 7 1 (Most Significant Bit) 17A8 = 0001 0111 10102 = 0000 0001 0111 1010 (16 bits)

4. 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 1. The method is find the weights (i.e., powers of 2) for each bit position that contains a 1, and then to add them up.

1 1 0 1 1 2 (binary) 24+23+0+21+20 = 16+8+0+2+1 = 2710 (decimal) 101101012 27+0+25+24+0+22+0+20 = 128+0+32+16+0+4+0+1 (binary)

= 18110 (decimal)

4. Binary to Decimal Conversion (Cont.)

Convert 1101012 to decimal number.


Binary Weights Weight Value Binary Number Decimal Value 25 24 23 22 21 20

32

16

32

16

Total (53)10

5. Binary to Octal Conversion

Each Octal digit is represented by three bits of binary digit.

Octal Digit 0 1 2 3 4 5 6 7 Binary Equivalent 000 001 010 011 100 101 110 111

Partition each binary number into 3-bit group to the left and right of the fractional point and then replacing each 3-bit group by its equivalent octal number. 1001110102 = (100) (111) (010)2 = 4728 10011.10112 =(010) (011).(101)(100)2 = 23.548

6. Binary to Hexadecimal

Each Hexadecimal digit is represented by four bits of binary digit.


Hexadecimal Digit Binary Equivalent Hexadecimal Digit Binary Equivalent 0 1 2 3 4 5 6 7 0000 0001 0010 0011 0100 0101 0110 0111 8 9 A B C D E F 1000 1001 1010 1011 1100 1101 1110 1111

Partition each binary number into 4-bit group to the left and right of the fractional point and then replacing each 4-bit group by its equivalent hexadecimal number. 1011001011112 = (1011) (0010) (1111)2 = B2F16 11011.1012 = (0001)(1011).(1010)2 = 1B.A16

7. Octal to Decimal Conversion

To express the value of a given octal number as its decimal equivalent we just need to sum the digits after each has been multiplied by its associated weight.

Convert (237.04)8 to decimal


Weights 82 81 80 8-1 8-2

Weight Value Octal Number Decimal Value

64

0.125

0.015625

128

24

0.0625

Total (159.0625)10

Again, 24.68= 2 x (81) + 4 x (80) + 6 x (8-1) = 20.7510

8. Octal to Binary Conversion

Each Octal digit is represented by three bits of binary digit.

Octal Digit 0 1 2 3 4 5 6 7 Binary Equivalent 000 001 010 011 100 101 110 111

For Octal to Binary conversion, convert each octal digit to its corresponding binary digits. 4728 = (100) (111) (010)2 = 1001110102 53.68 = (101)(011).(110)2 = 101011.112

9. Octal to Hexadecimal Conversion

Each Octal digit is represented by three bits of binary digit.

Octal Digit Binary Equivalent

0 1 2 3 4 5 6 7 000 001 010 011 100 101 110 111

1) Convert Octal to Binary first. 2) Partition each binary number into 4-bit group to the left and right of the fractional point and then replacing each 4-bit group by its equivalent hexadecimal number. 4728 = (100) (111) (010)2 = (0001) (0011) (1010)2 = 13A16

67.528 = (110)(111).(101)(010)2 = (0011)(0111).(1010)(1000)2 = 37.A816

10. Hexadecimal to Decimal Conversion

To express the value of a given hexadecimal number as its decimal equivalent, we just need to sum the digits after each has been multiplied by its associated weight.
Weights 162 161 160 . 16-1 16-2

The hexadecimal number is converted to decimal as follow: 2AF16 = 2 x (162) + 10 x (161) + 15 x (160) = 2 x 256 + 10 x 16 + 15 x 1 = 512+160+15 = 68710

11. Hexadecimal to Binary Conversion

Each Hexadecimal digit is represented by four bits of binary digit.


Hexadecimal Digit Binary Equivalent Hexadecimal Digit Binary Equivalent 0 1 2 3 4 5 6 7 0000 0001 0010 0011 0100 0101 0110 0111 8 9 A B C D E F 1000 1001 1010 1011 1100 1101 1110 1111

For Hexadecimal to Binary conversion, convert each hexadecimal digit to its corresponding 4-bit binary digit.

B2F16 = (1011) (0010) (1111)2 = 1011001011112


7.A3C16 = (0111).(1010)(0011)(1100) = 111.10100011112

12. Hexadecimal to Octal Conversion

Each Hexadecimal digit is represented by four bits of binary digit.


Hexadecimal Digit Binary Equivalent Hexadecimal Digit Binary Equivalent 0 1 2 3 4 5 6 7 0000 0001 0010 0011 0100 0101 0110 0111 8 9 A B C D E F 1000 1001 1010 1011 1100 1101 1110 1111

1) Convert Hexadecimal to Binary first. 2) Partition each binary number into 3-bit group to the left and right of the fractional point and then replacing each 3-bit group by its equivalent hexadecimal number.

B2F16 = (1011) (0010) (1111)2 = (101) (100) (101) (111)2 = 54578

THANK YOU ALL

Potrebbero piacerti anche