Menu

## Project Gimu

Software research and development

# Number Conversion Tricks

Curious about how to convert numbers from hexadecimal to binary as quick as possible? I’ve got good news for you, the following post contains methods to help you accomplish exactly that!

## 1.0 Conversion of Akin Bases

Assume we have to convert from one base to another ($a \rightarrow b$).

### 1.1 Higher Base to Lower Base

If we have to convert two bases in the form of $a = b^n$, then simply convert each digit from base $a$ to base $b$. Add leading zeroes to each converted digit until the length of $n$ has been reached. The last step is to combine them.

Example:
$6421_8 \rightarrow 110|100|010|001_2 \rightarrow 110100010001_2$

Each digit gets converted to binary and the last two resulting binary numbers also get leading zeroes (as $8 = 2^n \rightarrow n = 3$).

### 1.2 Higher Base to Lower Base

Furthermore, if we have to convert two bases in the form of $a^n = b$, then simply split the number in base $a$ in intervals of $n$ digits. Proceed to convert the resulting numbers from base $a$ to base $b$.

Example:
$231211_4 \rightarrow 23|12|11_4 \rightarrow B65_{16}$

The former number gets split in two-digit intervals (as $4^n = 16 \rightarrow n = 2$). The resulting numbers finally get converted from base $a$ to base $b$.

## 2.0 Conversion of Different Bases

If both bases do not have any correlation as seen above, proceed to use the following algorithm:

1. Divide the given number with the target base $b$. The division is done within base $a$.
2. Remember the remainder
3. Repeat step 1 with the result of the previous division (not the remainder!) until it becomes 0

Combine the remainders from bottom to top to get the desired result.