How to convert a hexadecimal number to an octal number?

How can I convert a hexadecimal number, for example 0x1A03 to its octal value?

I know that one way is to convert it to decimal and then convert it to octal

0x1A03 = 6659 = 0o15003
  • Is there a simple way to do it without the middle step (conversion to decimal or conversion to binary)?

  • Why do we tend to convert it to Base10 every time?


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.