How to Convert a Number from the Decimal System to the Binary System

Table of contents:

How to Convert a Number from the Decimal System to the Binary System
How to Convert a Number from the Decimal System to the Binary System
Anonim

The decimal number system (base ten) has ten possible symbols (0, 1, 2, 3, 4, 5, 6, 7, 8, or 9) for each place value. In contrast, the binary number system (base two) has only two possible symbols 0 and 1 to characterize each positional value. Since the binary system is the internal language used by all electronic devices, any programmer, to consider himself as such, would have to know how to convert from the decimal to the binary system. Here are some simple steps to learn how.

Steps

Method 1 of 2: Division by 2 with Rest

Convert from Decimal to Binary Step 1
Convert from Decimal to Binary Step 1

Step 1. Set the problem

In this example we will convert the decimal number 15610 in binary. Write the decimal number as a dividend in the symbol used for "column division". Write the base of the target system (in our case, "2" for the binary system) as the divisor to the left of the dividend and the sign used for the division.

  • This method is much easier to understand when viewing it on a sheet and easier for beginners as it is based on division by 2 only.
  • To avoid confusion before and after the conversion, write the number that distinguishes the base as a subscript. In this case, the decimal number will be written with the subscript 10 and the equivalent binary will have a subscript 2.
Convert from Decimal to Binary Step 2
Convert from Decimal to Binary Step 2

Step 2. Divide

Write the integer result (the quotient) under the division sign and write the remainder (0 or 1) to the right of the dividend.

Basically, since we divide by 2, if the dividend is even, the remainder will be 0, while if the dividend is odd, the remainder will be 1

Convert from Decimal to Binary Step 3
Convert from Decimal to Binary Step 3

Step 3. Continue going down, dividing each new quotient by two and writing the remainder to the right of each dividend

Continue until the quotient reaches 0.

Convert from Decimal to Binary Step 4
Convert from Decimal to Binary Step 4

Step 4. Write down the binary number thus obtained

Starting with the remainder that is further down, read the sequence of remainder values from bottom to top. In this example, the result is 10011100. This is the binary number equivalent to the decimal number 156, that is, using subscripts: 15610 = 100111002

This method can be easily modified to convert decimal numbers to any base. The divisor is 2 because the desired destination base in this example is base 2. If the desired destination base is another, replace the 2 used as divisor with the number corresponding to the desired base. For example, if the base you want to convert the decimal number to is base 9, replace the 2 with a 9. The final result will be the base 9 number corresponding to the starting decimal value

Method 2 of 2: Decreasing Powers of Two and Subtraction

Convert from Decimal to Binary Step 5
Convert from Decimal to Binary Step 5

Step 1. List the powers of 2 in a "base 2 table", from right to left

Start from 20, which corresponds to the value 1, continuing to the left. Increase the exponent by one unit at a time. Continue until you find a number very close to the decimal to convert. For example, let's convert 15610 in binary.

Convert from Decimal to Binary Step 6
Convert from Decimal to Binary Step 6

Step 2. Find out which is the greater power of two contained in the number you want to convert to binary

What is the greatest power of 2 contained in 156? It's 128: write a 1 for the first digit to the left of the binary number and subtract 128 from your decimal number, 156. You have 28 left.

Convert from Decimal to Binary Step 7
Convert from Decimal to Binary Step 7

Step 3. Go to the next decreasing power of 2

64 is contained in 28? No, so write a 0 for the second digit of the binary number, to the right of the 1 below 128. Continue until you find a number that can fit into 28.

Convert from Decimal to Binary Step 8
Convert from Decimal to Binary Step 8

Step 4. Subtract each subsequent number contained and mark it with a 1

16 can be in 28, so underneath you will write 1. Subtract 16 from 28 and you get 12. 8 is in 12, so underneath you write 1 and subtract 8 from 12. You will get 4.

Convert from Decimal to Binary Step 9
Convert from Decimal to Binary Step 9

Step 5. Continue until you reach the end of your pattern

Remember to mark a 1 under each number that is contained in your new number and a 0 under the one that does not.

Convert from Decimal to Binary Step 10
Convert from Decimal to Binary Step 10

Step 6. Write down the binary number

The number will be exactly the same string of 1s and 0s that appear below your list from left to right. You should get 10011100. This is the equivalent of the decimal 156 or, written with subscripts, 15610 = 100111002.

By repeating this method you will learn the powers of 2 by heart, so you can skip the first step

Advice

  • The calculator provided by your operating system is able to do this conversion for you, but if you are a programmer it is better that you have a good understanding of the conversion process. You can access the calculator's conversion options by clicking on the button View and selecting Programmer.
  • Conversion in the opposite direction, i.e. from the binary to the decimal system, is generally easier to learn first.
  • Exercise. Try converting the decimal numbers 17810, 6310 and 810. The binary equivalents are 101100102, 1111112 and 10002. Try converting 20910, 2510 and 24110 in, respectively, 110100012, 110012 and 111100012.

Recommended: