Skip to main content

Understanding numbers of informatics

· 4 min read
Strider

Hi, I would like to give a small tutorial about number systems in computer science.

Which number systems are commonly used in computer science?

  • Binary number system
  • Octal number system
  • Hexadecimal system

These three number systems are the most common in computer science with quite great importance. I would like to deal here also the conversions.

Let's get started. Let's assume we are to convert the decimal number 61 into a binary number. Binary numbers have the base 2 which means the number system consists of 2 numbers 0 and 1. Thus, all numbers from the decimal system can be represented.

The method we use is the residual method. This is one of the easiest methods. We take the number and divide it by 2. If we have something with 0.5 at the end, the remainder is 1 and the 0.5 are simply cut off. If the result is a smooth number, the remainder is 0. We do this until nothing is left. Only the rests are interesting, these are then read bottom-up. The whole thing can be checked for correctness here: https://www.binaryhexconverter.com/decimal-to-binary-converter

61/2=30.5 R=161 / 2 = 30.5\ R=1
30/2=15   R=030 / 2 = 15\ \ \ R=0
15/2=7    R=115 / 2 = 7\ \ \ \ R=1
7/2=3     R=17 / 2 = 3\ \ \ \ \ R=1
3/2=1     R=13 / 2 = 1\ \ \ \ \ R=1
1/2=0     R=11 / 2 = 0\ \ \ \ \ R=1

6110111101261_{10} \Leftrightarrow 111101_{2}

We can also exploit the power representation, but here it is easy to get muddled.

6110X261_{10} \rightarrow X_{2}

1286432168421
00111101

0011110121111012\rightarrow 00111101_{2} \Leftrightarrow 111101_{2}

0+0+32+16+8+4+0+1=61100+0+32+16+8+4+0+1 = 61_{10}

It is also possible to represent decimal numbers in the binary number system. Here we have to multiply everything behind the decimal point. As soon as we get over 1 in the multiplication, we have a 1, otherwise it is 0. E.g. we have the number 10.2410.24 as a decimal number. Let's convert that.

10.2410X210.24_{10} \rightarrow X_{2}

F1=10,F2=.24F1 = 10, F2 = .24

10/2=5  R=010 / 2 = 5\ \ R=0
5/2=2   R=15 / 2 = 2\ \ \ R=1
2/2=1   R=02 / 2 = 1\ \ \ R=0
1/2=0   R=11 / 2 = 0\ \ \ R=1
1010\rightarrow 1010

0.242=0.48 R=00.24 * 2 = 0.48\ R=0
0.482=0.96 R=00.48 * 2 = 0.96\ R=0
0.962=1.92 R=10.96 * 2 = 1.92\ R=1
0.922=1.84 R=10.92 * 2 = 1.84\ R=1
0.842=1.68 R=10.84 * 2 = 1.68\ R=1
0.682=1.36 R=10.68 * 2 = 1.36\ R=1
0.362=0.72 R=00.36 * 2 = 0.72\ R=0
0.722=1.44 R=10.72 * 2 = 1.44\ R=1
0.442=0.88 R=00.44 * 2 = 0.88\ R=0
0.882=1.76 R=10.88 * 2 = 1.76\ R=1
0.762=1.52 R=10.76 * 2 = 1.52\ R=1
0.522=1.04 R=10.52 * 2 = 1.04\ R=1
0.042=0.08 R=00.04 * 2 = 0.08\ R=0
0.082=0.16 R=00.08 * 2 = 0.16\ R=0
0.162=0.32 R=00.16 * 2 = 0.32\ R=0
0.322=0.64 R=00.32 * 2 = 0.64\ R=0
0.642=1.28 R=10.64 * 2 = 1.28\ R=1
......

10.24101010.00111101011100001...210.24_{10} \approx 1010.00111101011100001..._{2}

Why did I stop calculating further? Quite simply, it would take forever and three days.

Let's move on to the octal system. If you know or use Linux, you will have used the command chmod 755 or chmod 777 many times. Here we have octal numbers in play.

  • Read = 4
  • Write = 2
  • Execute = 1
  • 0...7

Suppose we want to convert the decimal number 61 into the octal system. The octal system has the base 8. The conversion is similar as before. Here, too, we use the remainder procedure.

6110X861_{10} \rightarrow X_{8}
61/8=7  R=5(0.6258)61 / 8 = 7\ \ R=5 \rightarrow (0.625 * 8)
7/8=0   R=7(0.8758)7 / 8 = 0\ \ \ R=7 \rightarrow (0.875 * 8)
0/8=0   R=0(08)0 / 8 = 0\ \ \ R=0 \rightarrow (0 * 8)
6110075875861_{10} \Leftrightarrow 075_{8} \Leftrightarrow 75_{8}

Another possibility is to convert the decimal number to the binary system, and from there to the octal system. This works like this:

6110111   1011111012        78   587561_{10} \\ \downarrow \\ \overbrace{ 111\ \ \ 101 }^{111101_{2}} \\ \downarrow\ \ \ \downarrow \\ \ \ \ \ \ 7_{8}\ \ \ 5_{8} \rightarrow 75

Assuming we want to convert from the decimal system to the hexadecimal system, we have to keep in mind that the hexadecimal system goes from 090-9 and from AFA-F. A=10,B=11,C=12,D=13,E=14,F=15.A = 10, B=11, C=12, D=13, E=14, F=15. Again, we can use the remainder method.

6110X1661_{10} \rightarrow X_{16}
61/16=3 R=D(0.812516=13)61 / 16 = 3\ R=D \rightarrow (0.8125 * 16 = 13)
3/16=0  R=3(0.187516=3)3 / 16 = 0\ \ R=3 \rightarrow (0.1875 * 16 = 3)
0/16=0  R=0(016=0)0 / 16 = 0\ \ R=0 \rightarrow (0 * 16 = 0)
03D163D1603D_{16} \Leftrightarrow 3D_{16}

The whole thing can be done from anywhere. No matter if Hex \rightarrow Bin, Oct \rightarrow Hex or Oct \rightarrow Dec...

This is the end of my tutorial. I hope I could bring the topic number systems in computer science, something closer 😄