How to convert a number to binary?

Sergey Nikolaev
Sergey Nikolaev
July 30, 2014
13151
How to convert a number to binary?

Writing numbers in the binary number system is performed using only two digits - 0 and 1. Therefore, this system is the easiest to implement in practice in electronic computers and devices. Consider how to convert a number to binary from the usual decimal without the help of a calculator and computer programs.

Whole numbers

In order to convert an integer from a decimal to a binary number system, it is necessary to divide it by two, and then divide by two each received quotient until a unit is obtained. The desired binary number is written as a sequence of digits equal to the last quotient (one) and all residues obtained, starting with the last one.

We give examples.

It is necessary to convert the number 23 to the binary system.

  1. 23: 2 = 11 (remainder 1)
  2. 11: 2 = 5 (remainder 1)
  3. 5: 2 = 2 (remainder 1)
  4. 2: 2 = 1 (remainder 0)

As a result, 2310 = 101112

The number 88 should be transferred to the binary number system:

  1. 88: 2 = 44 (remainder 0)
  2. 44: 2 = 22 (balance 0)
  3. 22: 2 = 11 (remainder 0)
  4. 11: 2 = 5 (remainder 1)
  5. 5: 2 = 2 (remainder 1)
  6. 2: 2 = 1 (remainder 0)

As a result, 8810= 10110002

Fractional numbers

Now consider an algorithm for how to convert fractional decimal numbers to binary. To do this, we work with the integer part of the number according to the procedure described above, and multiply the fractional part by two. The fractional part of the resulting work is again multiplied by two, and so on until the fractional part is zero or until the required approximation to the specified number of binary decimal places is obtained. The sought fractional part of a binary number is obtained as a sequence of digits after the comma equal to the integer parts of the resulting works, starting with the first.

Here are some examples:

You need to convert the number 5,625 to the binary system:

  • First consider the integer part of the decimal number:
    1. 5: 2 = 2 (remainder 1)
    2. 2: 2 = 1 (remainder 0)
  • In total, 510= 1012

  • Now the fractional part:
    1. 0,625 * 2 = 1,25
    2. 0,25 * 2 = 0,5
    3. 0,5 * 2 = 1,0

In total, 0.12510= 0,1012

As a result 5,62510= 101,1012

It is necessary to translate into a binary system 8.35 with an accuracy of up to 5 decimal places:

  • Let's start with the whole part:
    1. 8: 2 = 4 (remainder 0)
    2. 4: 2 = 2 (remainder 0)
    3. 2: 2 = 1 (remainder 0)
  • In total, 810= 10002

  • The fractional part of the number:
    1. 0,35 * 2 = 0,7
    2. 0,7 * 2 = 1,4
    3. 0,4 * 2 = 0,8
    4. 0,8 * 2 = 1,6
    5. 0,6 * 2 = 1,2

In total, 0.3510= 0,010112accurate to 5 decimal places.

As a result, 8.3510= 1000,010112accurate to 5 decimal places.