How to convert a hexadecimal number to an octal number?

A simpler way is to go through binary (base 2) instead of base 10.

0x1A03 = 0001 1010 0000 0011

Now group the bits in bunches of 3 starting from the right

0 001 101 000 000 011

This gives

0 1 5 0 0 3

Which is your octal representation.


I think the easiest way is to go through binary. A hex digit corresponds to 4 bits, an octal digit to 3.

0x1A03 in binary is 0001 1010 0000 0011 (grouped into 4-bit nibbles). If I regroup into 3-bit groups (from the right), I have 001 101 000 000 011. That's octal 0o15003.


When you're converting among bases $2^n$, you can often do so more quickly with a comprehensive conversion table. For example, between binary and octal, each block of 3 binary digits will convert to one octal digit: $$\begin{matrix} 000_2=0_8 & 001_2=1_8 & 010_2=2_8 & 011_2=3_8 \\ 100_2=4_8 & 101_2=5_8 & 110_2=6_8 & 111_2=7_8 \end{matrix}$$ Similarly, when converting between binary and hexadecimal, each block of 4 binary digits converts to a single hexadecimal digit. Because of these two facts, each block of 12 (least common multiple of 3 and 4) binary digits is 4 octal digits and 3 hexadecimal digits, so each block of 3 hexadecimal digits can be converted to a block of 4 octal digits. The table for doing hexadecimal<->octal directly is quite large, though, so it's usually simpler to convert to binary as an intermediate form.

It is also possible to do the conversion directly by performing division in octal or hexadecimal, though this can be tricky to get used to.

I think we tend to use decimal as an intermediate form because we are most familiar and comfortable with base 10 (since we generally have 10 fingers and use it most often).

Tags:

Arithmetic