# hexadecimal to decimal number

## Octal and hexadecimal numeration

Because binary numeration requires so many bits to represent relatively small numbers compared to the economy of the decimal system, analyzing the numerical states inside of digital electronic circuitry can be a tedious task. Computer programmers who design sequences of number codes instructing a computer what to do would have a very difficult task if they were forced to work with nothing but long strings of 1’s and 0’s, the “native language” of any digital circuit. To make it easier for human engineers, technicians, and programmers to “speak” this language of the digital world, other systems of place-weighted numeration have been made which are very easy to convert to and from binary.

One of those numeration systems is called *octal*, because it is a place-weighted system with a base of eight. Valid ciphers include the symbols 0, 1, 2, 3, 4, 5, 6, and 7. Each place weight differs from the one next to it by a factor of eight.

Another system is called *hexadecimal*, because it is a place-weighted system with a base of sixteen. Valid ciphers include the normal decimal symbols 0, 1, 2, 3, 4, 5, 6, 7, 8, and 9, plus six alphabetical characters A, B, C, D, E, and F, to make a total of sixteen. As you might have guessed already, each place weight differs from the one before it by a factor of sixteen.

Let’s count again from zero to twenty using decimal, binary, octal, and hexadecimal to contrast these systems of numeration:

Number Decimal Binary Octal Hexadecimal

—— ——- ——- —– ———–

Zero 0 0 0 0

One 1 1 1 1

Two 2 10 2 2

Three 3 11 3 3

Four 4 100 4 4

Five 5 101 5 5

Six 6 110 6 6

Seven 7 111 7 7

Eight 8 1000 10 8

Nine 9 1001 11 9

Ten 10 1010 12 A

Eleven 11 1011 13 B

Twelve 12 1100 14 C

Thirteen 13 1101 15 D

Fourteen 14 1110 16 E

Fifteen 15 1111 17 F

Sixteen 16 10000 20 10

Seventeen 17 10001 21 11

Eighteen 18 10010 22 12

Nineteen 19 10011 23 13

Twenty 20 10100 24 14

Octal and hexadecimal numeration systems would be pointless if not for their ability to be easily converted to and from binary notation. Their primary purpose in being is to serve as a “shorthand” method of denoting a number represented electronically in binary frm. Because the bases of octal (eight) and hexadecimal (sixteen) are even multiples of binary’s base (two), binary bits can be grouped together and directly converted to or from their respective octal or hexadecimal digits. With octal, the binary bits are grouped in three’s (because 2^{3} = 8), and with hexadecimal, the binary bits are grouped in four’s (because 2^{4} = 16):

BINARY TO OCTAL CONVERSION

Convert 10110111.1_{2} to octal:

.

. implied zero implied zeros

. | ||

. 010 110 111 100

Convert each group of bits ### ### ### . ###

to its octal equivalent: 2 6 7 4

.

Answer: 10110111.1_{2} = 267.4_{8}

We had to group the bits in three’s, from the binary point left, and from the binary point right, adding (implied) zeros as necessary to make complete 3-bit groups. Each octal digit was translated from the 3-bit binary groups. Binary-to-Hexadecimal conversion is much the same:

BINARY TO HEXADECIMAL CONVERSION

Convert 10110111.1_{2} to hexadecimal:

.

. implied zeros

. |||

. 1011 0111 1000

Convert each group of bits —- —- . —-

to its hexadecimal equivalent: B 7 8

.

Answer: 10110111.1_{2} = B7.8_{16}

Here we had to group the bits in four’s, from the binary point left, and from the binary point right, adding (implied) zeros as necessary to make complete 4-bit groups:

Likewise, the conversion from either octal or hexadecimal to binary is done by taking each octal or hexadecimal digit and converting it to its equivalent binary (3 or 4 bit) group, then putting all the binary bit groups together.

Incidentally, hexadecimal notation is more popular, because binary bit groupings in digital equipment are commonly multiples of eight (8, 16, 32, 64, and 128 bit), which are also multiples of 4. Octal, being based on binary bit groups of 3, doesn’t work out evenly with those common bit group sizings.

## Octal and hexadecimal to decimal conversion

Although the prime intent of octal and hexadecimal numeration systems is for the “shorthand” representation of binary numbers in digital electronics, we sometimes have the need to convert from either of those systems to decimal form. Of course, we could simply convert the hexadecimal or octal format to binary, then convert from binary to decimal, since we already know how to do both, but we can also convert directly.

Because octal is a base-eight numeration system, each place-weight value differs from either adjacent place by a factor of eight. For example, the octal number 245.37 can be broken down into place values as such:

octal

digits = 2 4 5 . 3 7

. – – – – – –

weight = 6 8 1 1 1

(in decimal 4 / /

notation) 8 6

. 4

The decimal value of each octal place-weight times its respective cipher multiplier can be determined as follows:

(2 x 64_{10}) + (4 x 8_{10}) + (5 x 1_{10}) + (3 x 0.125_{10}) +

(7 x 0.015625_{10}) = 165.484375_{10}

The technique for converting hexadecimal notation to decimal is the same, except that each successive place-weight changes by a factor of sixteen. Simply denote each digit’s weight, multiply each hexadecimal digit value by its respective weight (in decimal form), then add up all the decimal values to get a total. For example, the hexadecimal number 30F.A9_{16} can be converted like this:

hexadecimal

digits = 3 0 F . A 9

. – – – – – –

weight = 2 1 1 1 1

(in decimal 5 / /

notation) 6 1 2

. 6 5

. 6

(3 x 256_{10}) + (0 x 16_{10}) + (15 x 1_{10}) + (10 x 0.0625_{10}) +

(9 x 0.00390625_{10}) = 783.66015625_{10}

These basic techniques may be used to convert a numerical notation of *any* base into decimal form, if you know the value of that numeration system’s base.

## Conversion from decimal numeration

Because octal and hexadecimal numeration systems have bases that are multiples of binary (base 2), conversion back and forth between either hexadecimal or octal and binary is very easy. Also, because we are so familiar with the decimal system, converting binary, octal, or hexadecimal to decimal form is relatively easy (simply add up the products of cipher values and place-weights). However, conversion from decimal to any of these “strange” numeration systems is a different matter.

The method which will probably make the most sense is the “trial-and-fit” method, where you try to “fit” the binary, octal, or hexadecimal notation to the desired value as represented in decimal form. For example, let’s say that I wanted to represent the decimal value of 87 in binary form. Let’s start by drawing a binary number field, complete with place-weight values:

.

. – – – – – – – –

weight = 1 6 3 1 8 4 2 1

(in decimal 2 4 2 6

notation) 8

Well, we know that we won’t have a “1” bit in the 128’s place, because that would immediately give us a value greater than 87. However, since the next weight to the right (64) is less than 87, we know that we must have a “1” there.

. 1

. – – – – – – – Decimal value so far = 64_{10}

weight = 6 3 1 8 4 2 1

(in decimal 4 2 6

notation)

If we were to make the next place to the right a “1” as well, our total value would be 64_{10} + 32_{10}, or 96_{10}. This is greater than 87_{10}, so we know that this bit must be a “0”. If we make the next (16’s) place bit equal to “1,” this brings our total value to 64_{10} + 16_{10}, or 80_{10}, which is closer to our desired value (87_{10}) without exceeding it:

. 1 0 1

. – – – – – – – Decimal value so far = 80_{10}

weight = 6 3 1 8 4 2 1

(in decimal 4 2 6

notation)

By continuing in this progression, setting each lesser-weight bit as we need to come up to our desired total value without exceeding it, we will eventually arrive at the correct figure:

. 1 0 1 0 1 1 1

. – – – – – – – Decimal value so far = 87_{10}

weight = 6 3 1 8 4 2 1

(in decimal 4 2 6

notation)

This trial-and-fit strategy will work with octal and hexadecimal conversions, too. Let’s take the same decimal figure, 87_{10}, and convert it to octal numeration:

.

. – – –

weight = 6 8 1

(in decimal 4

notation)

If we put a cipher of “1” in the 64’s place, we would have a total value of 64_{10} (less than 87_{10}). If we put a cipher of “2” in the 64’s place, we would have a total value of 128_{10} (greater than 87_{10}). This tells us that our octal numeration must start with a “1” in the 64’s place:

. 1

. – – – Decimal value so far = 64_{10}

weight = 6 8 1

(in decimal 4

notation)

Now, we need to experiment with cipher values in the 8’s place to try and get a total (decimal) value as close to 87 as possible without exceeding it. Trying the first few cipher options, we get:

“1” = 64_{10} + 8_{10} = 72_{10}

“2” = 64_{10} + 16_{10} = 80_{10}

“3” = 64_{10} + 24_{10} = 88_{10}

A cipher value of “3” in the 8’s place would put us over the desired total of 87_{10}, so “2” it is!

. 1 2

. – – – Decimal value so far = 80_{10}

weight = 6 8 1

(in decimal 4

notation)

Now, all we need to make a total of 87 is a cipher of “7” in the 1’s place:

. 1 2 7

. – – – Decimal value so far = 87_{10}

weight = 6 8 1

(in decimal 4

notation)

Of course, if you were paying attention during the last section on octal/binary conversions, you will realize that we can take the binary representation of (decimal) 87_{10}, which we previously determined to be 1010111_{2}, and easily convert from that to octal to check our work:

. Implied zeros

. ||

. 001 010 111 Binary

. — — —

. 1 2 7 Octal

.

Answer: 1010111_{2} = 127_{8}

Can we do decimal-to-hexadecimal conversion the same way? Sure, but who would want to? This method is simple to understand, but laborious to carry out. There is another way to do these conversions, which is essentially the same (mathematically), but easier to accomplish.

This other method uses repeated cycles of division (using decimal notation) to break the decimal numeration down into multiples of binary, octal, or hexadecimal place-weight values. In the first cycle of division, we take the original decimal number and divide it by the base of the numeration system that we’re converting to (binary=2 octal=8, hex=16). Then, we take the whole-number portion of division result (quotient) and divide it by the base value again, and so on, until we end up with a quotient of less than 1. The binary, octal, or hexadecimal digits are determined by the “remainders” left over by each division step. Let’s see how this works for binary, with the decimal example of 87_{10}:

. 87 Divide 87 by 2, to get a quotient of 43.5

. — = 43.5 Division “remainder” = 1, or the < 1 portion
. 2 of the quotient times the divisor (0.5 x 2)
.
. 43 Take the whole-number portion of 43.5 (43)
. — = 21.5 and divide it by 2 to get 21.5, or 21 with
. 2 a remainder of 1
.
. 21 And so on . . . remainder = 1 (0.5 x 2)
. — = 10.5
. 2
.
. 10 And so on . . . remainder = 0
. — = 5.0
. 2
.
. 5 And so on . . . remainder = 1 (0.5 x 2)
. — = 2.5
. 2
.
. 2 And so on . . . remainder = 0
. — = 1.0
. 2
.
. 1 . . . until we get a quotient of less than 1
. — = 0.5 remainder = 1 (0.5 x 2)
. 2

The binary bits are assembled from the remainders of the successive division steps, beginning with the LSB and proceeding to the MSB. In this case, we arrive at a binary notation of 1010111_{2}. When we divide by 2, we will always get a quotient ending with either “.0” or “.5”, i.e. a remainder of either 0 or 1. As was said before, this repeat-division technique for conversion will work for numeration systems other than binary. If we were to perform successive divisions using a different number, such as 8 for conversion to octal, we will necessarily get remainders between 0 and 7. Let’s try this with the same decimal number, 87_{10}:

. 87 Divide 87 by 8, to get a quotient of 10.875

. — = 10.875 Division “remainder” = 7, or the < 1 portion
. 8 of the quotient times the divisor (.875 x 8)
.
. 10
. — = 1.25 Remainder = 2
. 8
.
. 1
. — = 0.125 Quotient is les than 1, so we'll stop here.
. 8 Remainder = 1
.
. RESULT: 87_{10 = 1278}

We can use a similar technique for converting numeration systems dealing with quantities less than 1, as well. For converting a decimal number less than 1 into binary, octal, or hexadecimal, we use repeated multiplication, taking the integer portion of the product in each step as the next digit of our converted number. Let’s use the decimal number 0.8125_{10} as an example, converting to binary:

. 0.8125 x 2 = 1.625 Integer portion of product = 1

.

. 0.625 x 2 = 1.25 Take < 1 portion of product and remultiply
. Integer portion of product = 1
.
. 0.25 x 2 = 0.5 Integer portion of product = 0
.
. 0.5 x 2 = 1.0 Integer portion of product = 1
. Stop when product is a pure integer
. (ends with .0)
.
. RESULT: 0.8125_{10 = 0.11012}

As with the repeat-division process for integers, each step gives us the next digit (or bit) further away from the “point.” With integer (division), we worked from the LSB to the MSB (right-to-left), but with repeated multiplication, we worked from the left to the right. To convert a decimal number greater than 1, with a < 1 component, we must use *both techniques, one at a time. Take the decimal example of 54.40625 _{10}, converting to binary:*

REPEATED DIVISION FOR THE INTEGER PORTION:

.

. 54

. — = 27.0 Remainder = 0

. 2

.

. 27

. — = 13.5 Remainder = 1 (0.5 x 2)

. 2

.

. 13

. — = 6.5 Remainder = 1 (0.5 x 2)

. 2

.

. 6

. — = 3.0 Remainder = 0

. 2

.

. 3

. — = 1.5 Remainder = 1 (0.5 x 2)

. 2

.

. 1

. — = 0.5 Remainder = 1 (0.5 x 2)

. 2

.

PARTIAL ANSWER: 54_{10} = 110110_{2}

REPEATED MULTIPLICATION FOR THE < 1 PORTION:
.
. 0.40625 x 2 = 0.8125 Integer portion of product = 0
.
. 0.8125 x 2 = 1.625 Integer portion of product = 1
.
. 0.625 x 2 = 1.25 Integer portion of product = 1
.
. 0.25 x 2 = 0.5 Integer portion of product = 0
.
. 0.5 x 2 = 1.0 Integer portion of product = 1
.
. PARTIAL ANSWER: 0.40625_{10 = 0.011012
.
. COMPLETE ANSWER: 5410 + 0.4062510 = 54.4062510
.
. 1101102 + 0.011012 = 110110.011012}

**Related**

COMMENTsongs