Number systems conversion

There are four widely used number systems: decimal (10), binary (2), octal (8), and hexadecimal (16). As humans, we use the decimal system.

Name Symbols Notation
decimal 0, 1, 2, 3, 4, 5, 6, 7, 8, 9 759, 100
binary 0, 1 1012, 1101B
octal 0, 1, 2, 3, 4, 5, 6, 7 3578, 156O
hexadecimal 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A (10), B (11), C (12), D (13), E (14), F(15) F516, ABCH

The color blue on the examples below indicates which part we write first.

When converting dec to bin, we must write the powers of 2 from the right side to the moment the next power will be bigger than the number we want to convert. Then, going from the left, we write 1 above a value and subtract it from our main number. We continue the process, but if a number is too large to subtract without receiving a negative number, we write 0 above it and go on. When converting bin to dec, we invert the process and note the powers of 2 under the binary number. Then, we add the numbers that have 1 above them.

Img

When converting bin to hex, we divide the number by a line every four digits and write (from the right side) the first four powers of 2 under each set of them. Then, we do something similar to the previous conversion. We add the powers of 2 that have 1 above them from every set of four digits separately. Our final number is the conjunction of all the results into one string. When converting hex to bin, we invert the process.

Img

When converting dec to hex, we must divide the number by %16 (modulo 16) and write the result on the other side of the line. We must also write the rounded outcome of a normal division below the divided number and continue the process using this number. After we finished, we read the number from the bottom to the top. When converting hex to dec, we take every digit / letter from this number (from the right side), and multiply them by succeeding powers of sixteen. When converting dec to oct and vice versa, we use the same methods, but we divide and multiply by 8.

Img

When converting bin to oct, we have to do the same thing as the conversion from bin to hex, but we divide the number with lines every three digits. Conversion directly from hex to oct, and vice versa, is impossible. We have to do it indirectly through binary.

Img

When we convert the symbols from hexadecimal to zeros and ones, we write them on four bits (four digits), and when we convert them from octal, we write them on three bits.

Hexadecimal Binary (Hex) Octal Binary (Oct)
0 0000 0 000
1 0001 1 001
2 0010 2 010
3 0011 3 011
4 0100 4 100
5 0101 5 101
6 0110 6 110
7 0111 7 111
8 1000 - -
9 1001 - -
A 1010 - -
B 1011 - -
C 1100 - -
D 1101 - -
E 1110 - -
F 1111 - -