Binary/decimal

Base 10

Everyone knows how to count in base 10 (decimal system). But how does it work?

In base 10, we use 10 digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

With these 10 digits, we can count effortlessly from 0 to 9. But how do we do it afterwards? The problem arises when the units rank is full. Well, when it's full, we change rank, and move to the tens rank, then hundreds, thousands, etc.

Thus, we count up to 9, then the rank is full, so we add one unit to the tens rank, and start over... until we fill the tens rank. We then start filling the hundreds, etc.

Thus, for example for the value 29, we can no longer increment the units rank, so we increment the higher rank (tens), and reset the lower ranks (units) to 0.

We are here in base 10, so:

  • one hundred equals 10 tens
  • one ten equals 10 units
  • etc.
We can therefore decompose any number in base 10: 384 = 3 * 100 + 8 * 10 + 4 * 1 384 = 3 * 10² + 8 * 10¹ + 4 * 10⁰

Base 2

A computer is composed of circuits and electronic components. The simplest way, to count, is therefore to use a base 2 system that can translate two states:

Presence of current: state 1 Absence of current: state 0

If we want to apply the same logic seen previously to base 2, we just need to transpose these same rules to a base value set composed of two elements: 0 and 1.

We decompose the binary number to get its decimal value: (1101)2=(123+122+021+120)10(1101)_2 = (1 * 2³ + 1 * 2² + 0 * 2¹ + 1 * 2⁰)_{10}(1101)2=(222+22+0+1)10(1101)_2 = (2*2*2 + 2*2 + 0 + 1)_{10}(1101)2=(8+4+1)10(1101)_2 = (8 + 4 + 1)_{10}(1101)2=(13)10(1101)_2 = (13)_{10}

The method for converting a number from base 10 to base 2 is simple:

  1. the decimal value is divided by 2, we keep the quotient and the remainder equals 0 or 1
  2. the quotient from the previous step is divided by 2, we keep the new quotient and the remainder equals 0 or 1
  3. we repeat step 2 until we get a quotient equal to 0.

Base 16

In daily life, with our 10 fingers, base 10 is perfectly suited. In computing, closest to the machine, everything is coded in base 2.

But in computing, since everything is based on binary, it's easier to encode information in a base that would be a multiple of 2, so we very often use base 16.

NameBaseUnits
decimal100 1 2 3 4 5 6 7 8 9
binary20 1
hexadecimal160 1 2 3 4 5 6 7 8 9 A B C D E F

The method for converting a number from base 2 to base 16 is simple:

  1. We group the bits 4 by 4: with 4 bits, we encode at most 16 values
  2. Each packet of 4 bits is converted to its hexadecimal value

For conversion in the other direction, it's just as simple:

  1. Each hexadecimal value is converted to its binary equivalent

We use the following correspondence table:

Binary (base 2)Decimal (base 10)Hexadecimal (base 16)
000000
000111
001022
001133
010044
010155
011066
011177
100088
100199
101010A
101111B
110012C
110113D
111014E
111115F