# converting to octal, hexadecimal and binary

Revising for an exam - could someone explain to me how you can convert an ordinary numbers to octal, hexadecimal and binary

would be appreciated

-
There are good answers here; you might want o accept one. – ncmathsadist Jan 3 '14 at 20:43

Work on converting a decimal integer to binary. Then octal & hexadecimal follow just by grouping the digits in groups of 3 or 4 respectively.

To convert to binary, repeatedly divide by 2 and collect the remainders (which must all be either 0 or 1) until you reach zero. The binary representation is then given by the remainders, starting with the last first.

For example, take $23$. Dividing by $2$ repeatedly gives the sequence $11+1$, $5+1$, $2+1$, $1+0$, $0+1$. Reading the remainders in reverse gives $23_{10} = 1 0 1 1 1_2$.

-

Fastest way is to divide by base repeatedly. Here is an example

Convert 1000-decimal to hex

$$1000 = 62 \times 16 + 8 \\ 62 = 3 \times 16 + 14 \\ 3 = 0 \times 16 + 3$$ now write all the remainders in hex $3\rightarrow3$, $14\rightarrow E$, and $8 \rightarrow 8$ and read it bottom to top to get

1000-decimal = 3E8-hex

The last digit of a number $n$ in base $b$ is the remainder of $n$ divided by $b$. The other digits are the digit of the integer quotient $n/b$.
Hence the algorithm: make the integer division $n/b$. Write the rest and repeat the algorithm with $n$ replace by the quotient. Write the rest as digits from right to left.