3.

[Top] [Next] [Prev]

A.2 Conversion Between Binary, Octal, and Hexadecimal Systems

We cover the methods for converting between the various binary-based systems in this subsection.

A.2.1 Conversion from Binary to Octal or Hexadecimal

It is always easy to rewrite a binary number in the octal or hexadecimal system. All we have to do is group the binary digits into 3-bit groupings (octal) or 4-bit groupings (hexadecimal), starting at the right of the number. For example, starting with the binary number 100110102, we derive its octal and hexadecimal equivalents as follows:

To see why this grouping strategy is correct, let's look at a generalized representation of a binary number and how we convert it to a hexadecimal number. We assume that the binary number always has a multiple of 4 bits. Of course, for any binary number, we can prepend additional zeros to the most significant bits to make this assumption true.

The generalized representation is shown below. The binary number starts out with n bits and will be converted to a hexadecimal number with k = n/4 hex digits:

The process of putting the bits into groups of four is equivalent to factoring powers of 16 within the expression. By doing the grouping, we can rewrite the generalized expression as follows:

We can now rewrite each of the 4-bit numbers in the parentheses as a single hexadecimal digit, raised to an appropriate power of 24. We could apply a similar method to demonstrate why grouping by threes performs the conversion from binary to octal.

A.2.2 Conversion from Octal to Hexadecimal and Vice Versa

To convert between octal and hexadecimal, you should first convert the number into binary. By appropriate grouping of bits, you then form the number in the target base. Let's see how this works for the conversion between 2328 and 9A16:

2328 maps into the binary number 010 011 0102, which can be re-grouped to form the number 9A16. The mapping from hex to octal works analogously.

A.2.3 Conversion from Base 10 to Base 2: Successive Division

So far, you have seen how to map binary, octal, and hexadecimal numbers into base 10, by expanding the positional notation. You have also seen how to map between the binary system and the octal and hex systems. The missing link is how to get from base 10 to base 2.

The method we use is called successive division. It works by successively dividing the base 10 number by the base to which it is to be converted. For example, we successively divide by 2 if the target is base 2. We collect the remainders to form the number in the target base. The first division yields the least significant bit as its remainder. The process continues until the quotient is 0.

Let's look at an example: the conversion of 15410 to base 2. The process is as follows:

The same method works for conversion from base 10 to other bases. For example, to convert 15410 to base 8, we proceed as follows:

The conversion to base 16 works like this:

The Theory Behind Successive Division Given that the number N in base 10 is equivalent to an n-digit number in a different base R, we should be able to rewrite N in base R as (an-1 an-2 a0)R. As we successively divide by R, each subsequent division liberates the next lower-order digit ai from the base R representation.

To see this, consider the following description of successive division. Since N is represented as an n-digit number in base R, the first division yields the quotient Q0 and the remainder a0. The latter is exactly the value of the lowest-order digit in base R. Dividing R into Q0 results in a new quotient Q1 and a new remainder a1, the next lowest-order digit. If we repeat the process n times, we obtain a quotient of zero and a remainder that is equal to the highest-order digit in base R. The process of successive division is shown below:

To summarize, Figure A.1 shows the various conversion methods that we have covered. We use successive division to convert from base 10 to any other base. By expanding the positional notation, we can convert from any base to base 10. We perform conversions between base 2 and other bases that are powers of two, such as base 8 and base 16, through the process of bit grouping.


[Top] [Next] [Prev]


This file last updated on 07/16/96 at 05:10:10.
randy@cs.Berkeley.edu;


What is Sarbanes-Oxley[q]
What is Sarbanes-Oxley[q]
ISBN: 71437967
EAN: N/A
Year: 2006
Pages: 101

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net