An introduction to Binary

Some blurry binaryThe Binary, or base-2 number system,  is represented by the symbols 1 and 0. It’s used in most digital electronic circuits and all desktop computers in the world. Because of this, a basic understanding of binary is extremely important to a computer scientist.

Why Binary and not Decimal?

Everyone’s familiar with Decimal. It’s the number system we all use every day – and for good reason – we have 10 fingers and 10 toes. For a humans it just makes sense.

When working with electronics however, 10 different states isn’t easy to represent, especially when working with low voltages. Noise is  huge problem, as is deciding which voltage represents each state. Try to implement a digital circuit which uses more than 2 states and you’ll get yourself into a whole lot of bother. Binary is perfect for digital circuits, very low voltages correspond to 0 and high voltages 1.

In this graph, anything above the top dotted line represents a 1 and everything below the bottom line represents a 0.

The use of binary makes circuits and hardware much more stable and less prone to noise. It makes them simpler too, without the use of binary, digital circuits would be nowhere near as advanced as they are today.

We can use very simple building blocks with simple rules to take billions of  transistors and create insanely powerful hardware that’s fast, stable and cheap.

How do I convert from Decimal to Binary?

So lets recap. Binary is a base-2 number system, that means it only has 2 symbols, 1 and 0, to represent every number. This sounds insane but its actually very simple and doing maths with it is similar and can be done in the same way you were first taught how to add and subtract decimal numbers when you were young.

Let’s start of by converting from a decimal number, such as 14, to binary. It’s actually fairly simple. Binary is read from right to left and every digit represent a power of 2. You’re probably familiar with the powers of 2, they’re very recognisable and crop up all the time in computers, the first few are 1, 2, 4, 8, 16, 32, 64 and 128.

There are a number of ways to convert from decimal to binary, some are faster than others but they all work. We’ll start with the simplest one first. It involves dividing the number by 2 and taking the remainder as the binary digit. Every time we divide by 2 we are increasing the power of 2. This method is best given as an example:

MATHS                           BINARY NUMBER SO FAR
14 ÷ 2 = 7 remainder 0          0
 7 ÷ 2 = 3 remainder 1          10
 3 ÷ 2 = 1 remainder 1          110
 1 ÷ 2 = 0 remainder 1          1110

So starting with 14 and dividing by 2 we get 7 with 0 remaining. It the remainder that is important here as it’s our binary digit. Note it down and repeat the steps again with 7. This time we have a remainder of 1. This is our second binary digit and it goes to the left of the 0 giving us 10. Remember, when using binary we read and write from right to left. Doing the same again with 3 gives us another 1 (110) and finally repeating the process again gives us 1 which means that 14 in binary is 1110.

Converting from Binary to Decimal

Converting from binary to decimal is very simple. My favorite method for doing so is to write out the binary number and above each digit write the powers of 2. I then sum all of the powers which have a 1 below them to get the decimal value.

Powers of 2:   16   8   4   2   1
Binary:         1   1   0   0   1
Decimal:       16 + 8 + 0 + 0 + 1 = 25

We can use this to check that the binary value we got for 14 earlier is correct.

Powers of 2:   8   4   2   1
Binary:        1   1   1   0
Decimal:       8 + 4 + 2 + 0 = 14

I’ve included a table with the decimal numbers from 0 to 31 and their binary counterparts below.

Binary    Decimal   |   Binary    Decimal
000000       0      |   010000      16
000001       1      |   010001      17
000010       2      |   010010      18
000011       3      |   010011      19
000100       4      |   010100      20
000101       5      |   010101      21
000110       6      |   010110      22
000111       7      |   010111      23
001000       8      |   011000      24
001001       9      |   011001      25
001010      10      |   011010      26
001011      11      |   011011      27
001100      12      |   011100      28
001101      13      |   011101      29
001110      14      |   011110      30
001111      15      |   011111      31

Leave a Reply

Spam Protection by WP-SpamFree