You are on page 1of 29

Decimal-to-Binary Conversions

Converting Decimal Fractions to Binary


Repeated Multiplication Method

Decimal-to-Binary Conversions
Convert the decimal fraction 0.188 to binary by
repeatedly multiplying the fractional results by 2.

MSB
0.188 x 2 = 0.376
carry = 0
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
Answer = .00110 (for five significant digits)

Hexadecimal Numbers
Hexadecimal uses sixteen characters to
represent numbers: the numbers 0
through 9 and the alphabetic characters A
through F.
Large binary number can easily be
converted to hexadecimal by grouping
bits 4 at a time and writing the equivalent
hexadecimal character.

Decimal Hexadecimal Binary

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

Hexadecimal Numbers
Hexadecimal is a weighted number
system. The column weights are
powers of 16, which increase from
right to left.

Column weights

163 162 161 160.


4096 256 16 1 .

Decimal Hexadecimal Binary

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

Hexadecimal Numbers
Counting in Hexadecimal
With two hexadecimal digits, you can
count up to FF16 , which is decimal 255.
To count beyond this, three
hexadecimal digits are needed.
10016 is decimal 256, 10116 is decimal
257.
The maximum 3-digit hexadecimal
number is FFF16 or decimal 4095.

Decimal Hexadecimal Binary

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

0
1
2
3
4
5
6
7
8
9
A
B
C
D
E
F

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

Hexadecimal Numbers
Binary-to-Hexadecimal Conversion
Converting a binary number to hexadecimal simply break
the binary number into 4-bit groups, starting at the rightmost bit and replace each 4-bit group with the equivalent
hexadecimal symbol.
Express 1001 0110 0000 11102 in
hexadecimal:
Group the binary number by 4-bits
starting from the right. Thus, 960E

Hexadecimal Numbers
Binary-to-Hexadecimal Conversion

Hexadecimal Numbers
Hexadecimal-to-Binary Conversion
To convert from a hexadecimal number to a binary number,
reverse the process and replace each hexadecimal symbol
with the appropriate four bits.

Hexadecimal Numbers
Hexadecimal-to-Decimal Conversion
One way to find the decimal equivalent of a hexadecimal
number is to first convert the hexadecimal number to binary
and then convert from binary to decimal.

Hexadecimal Numbers
Hexadecimal-to-Decimal Conversion
Another way to convert a hexadecimal number to its
decimal equivalent is to multiply the decimal value of each
hexadecimal digit by its weight and then take the sum of
these products.
Express 1A2F16 in decimal.
Start by writing the column weights:
4096 256 16 1
1
A 2 F16
1(4096) + 10(256) +2(16) +15(1) = 670310

Hexadecimal Numbers
Hexadecimal-to-Decimal Conversion

Hexadecimal Numbers
Decimal-to-Hexadecimal Conversion
Repeated division of a decimal number by 16 will produce
the equivalent hexadecimal number, formed by the
remainders of the divisions.
The first remainder produced is the least significant digit
(LSD). Each successive division by 16 yields a remainder
that becomes a digit in the equivalent hexadecimal number.
When a quotient has a fractional part, the fractional part
is multiplied by the divisor to get the remainder.

Hexadecimal Numbers
Decimal-to-Hexadecimal Conversion

Octal Numbers
Octal uses eight characters the numbers
0 through 7 to represent numbers.
There is no 8 or 9 character in octal.
To count above 7, begin another column
and start over:
10, 11, 12. 13, 14, 15, 16. 17,20,21,...
Octal is a convenient way to represent
binary numbers, but it is not as
commonly used as hexadecimal.

Decimal

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Octal

Binary

0
1
2
3
4
5
6
7
10
11
12
13
14
15
16
17

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

Octal Numbers
Octal is also a weighted number system. The column
weights are powers of 8, which increase from right to left.
Column weights

83 82
512 64

81
8

80 .
1 .

Octal-to-Decimal Conversion
The evaluation of an octal number in terms of its decimal equivalent is
accomplished by multiplying each digit by its weight and summing the
products,
Express 37028 in decimal.
Start by writing the column weights:
512 64 8 1
3 7 0 28
3(512) + 7(64) +0(8) +2(1) = 198610

Octal Numbers
Decimal-to-Octal Conversion
A method of converting a decimal number to an octal number
is the repeated division-by- 8 method, which is similar to the
method used in the conversion of decimal numbers to binary
or to hexadecimal.
The first remainder generated is the least significant digit
(LSD).

Octal Numbers
Decimal-to-Octal Conversion
Convert the decimal number 359 to octal. .

Octal Numbers
Octal-to-Binary Conversion
Binary number can easily be converted to octal by
grouping bits 3 at a time and writing the equivalent octal
character for each group.

Express 1 001 011 000 001 1102 in


octal:
Group the binary number by 3-bits
starting from the right. Thus, 1130168

Octal Numbers
Octal-to-Binary Conversion

Octal Numbers
Binary-to-Octal Conversion
The procedure is as follows: Start with the right-most
group of three bits and, moving from right to left,
Convert each 3-bit group to the equivalent octal digit.
If there are not three bits available for the left-most group,
add either one or two zeros to make a complete group.
These leading zeros do not affect the value of the binary
number.

Octal Numbers
Binary-to-Octal Conversion

BCD
Binary Coded Decimal (BCD) code is used to represent
decimal digits in binary. BCD code is a 4-bit binary code;
the first 10 combinations represent the decimal digits 0 to
9.
The remaining six 4-bit combinations 1010, 1011, 1100,
1101, 1110 and 1111 are considered to be invalid and do
not exist.
Binary coded decimal (BCD) is a weighted code that is
commonly used in digital systems when it is necessary to
show decimal numbers such as in clock displays.
A telephone keypad having the digits 0 to 9 generates BCD
codes for the keys pressed.

BCD
The table 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.
To write 17, two BCD code for 1
and 7 are used 0001 and 0111.
The two digits are considered to
be separate.

Decimal

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

Binary

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

BCD

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
0001 0000
0001 0001
0001 0010
0001 0011
0001 0100
0001 0101

BCD
The ease of conversion between 8421 code numbers and
the familiar decimal numbers is the main advantage of
this code.

BCD
You can think of BCD in terms of column weights in
groups of four bits. For an 8-bit BCD number, the column
weights are: 80 40 20 10 8 4 2 1.
What are the column weights for the BCD number
1000 0011 0101 1001?
8000 4000 2000 1000 800 400 200 100 80 40 20 10

8 4 2 1

Note that you could add the column weights where there is
a 1 to obtain the decimal number. For this case:
8000 + 200 +100 + 40 + 10 + 8 +1 = 835910

Gray code
Gray code is an unweighted code
that has a single bit change between
one code word and the next in a
sequence. Gray code is used to
avoid problems in systems where an
error can occur if more than one bit
changes at a time.

Decimal

Binary

Gray code

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000

Gray code
Like binary numbers. the Gray code can
have any number of bits.
Notice the single-bit change between
successive Gray code words.
For instance, in going from decimal 3 to
decimal 4, the Gray code changes from
0010 to 0110, while the binary code
changes from 0011 to 01 00, a change of
three bits.
The only bit change is in the third bit from
the right in the Gray code; the others
remain the same.

Decimal

Binary

Gray code

0
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15

0000
0001
0010
0011
0100
0101
0110
0111
1000
1001
1010
1011
1100
1101
1110
1111

0000
0001
0011
0010
0110
0111
0101
0100
1100
1101
1111
1110
1010
1011
1001
1000

Gray code
Binary-to-Gray Code Conversion
The following rules explain how to convert from a binary number to a
Gray code word:
1. The most significant bit (left-most) in the Gray code is the same as the
corresponding MSB in the binary number.
2. Going from left to right, add each adjacent pair of binary code bits to
get the next Gray code bit. Discard carries.

For example, the conversion of the binary number 10110 to


Gray code is as follows:

The Gray code is 11101.

Gray code
Gray-to-Binary Conversion
The following rules apply:
1. The most significant bit (left-most) in the binary code is the same as
the corresponding bit in the Gray code.
2. Add each binary code bit generated to the Gray code bit in the next
adjacent position. Discard carries.

For example, the conversion of the Gray code word 11011 to


binary is as follows:

The binary number is 10010.

You might also like