Converting between number bases
Binary, octal, hexadecimal and bases from 3 to 9: convert to decimal and back, and between 2, 8 and 16 directly, in groups of bits.
How to solve it
In decimal a digit is worth what its place allows: in $352$ the three means three hundreds. In base $b$ it works the same way, only the places are powers of $b$: ones, $b$, $b^2$, $b^3$ and so on.
Step by step
- To decimal: multiply each digit by the value of its place ($b^0, b^1, b^2, \dots$ from right to left) and add.
- From decimal: divide the number by $b$ with a remainder, then the quotient by $b$ again, until the quotient is zero. The remainders read from the bottom up are the digits.
- Digits above nine in hexadecimal are letters: $A = 10$, $B = 11$, …, $F = 15$.
- Between $2$, $8$ and $16$ decimal is not needed: one octal digit is $3$ bits, one hexadecimal digit is $4$ bits. Count the groups from the right.
Common mistakes
- Reading the remainders top down gives the number backwards. The last remainder is the leading digit.
- Starting the place values at $b^1$ instead of $b^0$: the rightmost digit is worth $1$.
- Grouping bits from the left instead of the right: $101110000_2$ in fours from the right is $1\,0111\,0000$, that is $170_{16}$.
- Writing a digit equal to the base: binary has no digit $2$, octal has no $8$.