answersLogoWhite

0

There are two methods that are essentially the same but attack the problem from opposite ends. An example, below, illustrates both for integer numbers.

First, note that since the hexadecimal base is 16, you need 16 different "digits". These are the Hindu-Arabic digits supplemented by A (= decimal 10), B (11), C(12), D(13), E(14) and F(15).

The first method is simpler since you are only dividing by 16 but it works only for integer decimals and, until you get to the end, there is no indication of how many digits the hexadecimal number will have. The second method requires division by large numbers (powers of 16). But from the start (see below) the number of hexadecimal digits are known. It is therefore possible to stop after a few iterations if only an estimate (a given number of significant digits) is required. Also, the method can be used for fractions: continue after 160 utilising 16-1 (=1/16), 16-2 (=1/256), and so on until the desired level of accuracy is reached.

Method 1:

Suppose the Hindu Arabic number is D.

Divide D by 16 so that you get a quotient Q and reminder R.

Then the rightmost digit of the hexadecimal is R.

Replace D by Q and divide this by 16 so that the new quotient is Q and the remainder is R.

Then the digit to the left of the previous value of R is the new one.

Replace D by Q and continue division by 16 until Q <16.

At that stage the digit to the left of the previous value of R is the next value of R and the one before that is Q.

Method 2:

First draw up a list of the integer powers of 16 so that the biggest power is bigger than D. Reject that one.

So you have 16a <= D but 16a+1 > D for some integer a. The hexadecimal will have a+1 digits.

Divide D by 16a giving a quotient Q and remainder R.

Then Q is the leftmost first) digit of the hexadecimal number.

Replace D by R and repeat with 16a-1. This step will give you the second digit of the hexadecimal. With integer decimals, continue until division by 16, when the final digit is R. With decimal fractions continue after the "decimal" point until you have the desired level of accuracy.

Examples:

Method 1

Suppose the decimal integer, D = 123456

The number of digits in the hexadecimal is not known but it will not exceed the number of decimal digits - ie 6.

Divide 123456 by 16: Q = 7716 and R = 0

So the hexadecimal is ?????5, and the new D = 7716.

Divide 7716 by 16: Q = 482 and R = 4

So the hexadecimal is ????45, and the new D = 482.

Divide 482 by 16: Q = 30 and R = 2

So the hexadecimal is ???215 and the new D = 30.

Divide 482 by 16: Q = 1 and R = 14

So the hexadecimal is ??E215 and since Q < 16 this is the last iteration and the hexadecimal is 1E215.

Method 2

The powers of 16 are:

160 = 1, 161 = 16, 162 = 256, 163 = 4096, 164 = 65536 , 165 = 1048576 which is bigger than D.

Thus 164 < D < 165. Therefore the hexadecimal number contains 5 digits.

Divide 123456 by 164 = 65536: Q = 1 and R = 57920

So the hexadecimal is 1???? and the new D is 57920.

Divide 57920 by 163 = 4096: Q = 14 and R = 576

So the hexadecimal is 1E??? and the new D is 576.

Divide 576 by 162 = 256: Q = 2 and R = 64

So the hexadecimal is 1E2?? and the new D is 64.

Divide 64 by 161 = 16: Q = 4 and R = 0

So the hexadecimal is 1E24?.

Since that is the division by 161, the final digit of the hexadecimal is R that is the hexadecimal is 1E240.

User Avatar

Wiki User

10y ago

What else can I help you with?