Learn the binary number system

Dalha Dalha
Dalha Dalha
Currently a student and a computer enthusiast
18 Views
11 Min Read

The binary number system is the foundation of every digital device, from smartphones and laptops to satellites and supercomputers. Most people should be familiar with the decimal (base-10) number system in which the digits are numbered from 0 to 9. The binary system on the other hand is a base-2 system. Computers rely on this system for storage, processing, and transmitting of data.

So why do computers only use the binary system and not any other?

Well, binary uses only two digits (0 and 1) , which actually aligns perfectly with the on/off nature of electronic circuits. Getting to understanding how binary works is not only essential for computer scientists and engineers, but also for anyone looking to build a strong reliable foundation in anything computing.

In this article, we will learn what the binary number system is, how to count using it, how to covert between binary and decimal numbers, and also learn how to perform all the basic arithmetic operations using the system.

Let’s begin!

What is the binary number system?

The binary number system is a base-2 number system that uses only two digits: 0 and 1. Unlike the decimal system, which is based on powers of 10, the binary system is based on powers of 2. Each digit in a binary number represents an increasing power of 2, starting from the rightmost digit.

Binary vs decimal

Decimal (Base 10)Binary (Base 2)
00
11
210
311
4100
5101

How to count in the binary number system

Counting in the binary number system might seem daunting at first since we all grew up counting using the decimal system, but once you understand the pattern, it becomes really easy and useful especially if you are going on to learning other numbering systems. You’ll learn that the pattern is actually used by all numbering systems.

The counting basics

Just like base-10 counting, binary starts at 0 and increments by 1. The point at which the two differ is the limit of the highest number.  Binary only allows two digits (0 and 1) whilst the decimal system uses (0 to 9).

Here is a table showing binary counting from 0 to 15:

DecimalBinary
00000
10001
20010
30011
40100
50101
60110
70111
81000
91001
101010
111011
121100
131101
141110
151111

Binary conversion

Binary to decimal conversion

Converting from binary to decimal is at the foundation of understanding how numbers are represented inside computers. Once you know the method, it will become a very simple process.

The positional method

Each digit (bit) in a binary number represents a power of 2, this starts from the rightmost digit which is also known as the least significant bit (LSB).

For us to convert binary to decimal, we  multiply each bit by \(2n2^n2n\), where n is the position index starting from 0 on the right.

Decimal to binary conversion

Just like how we converted binary numbers to decimal, we can also do it the other way around. This becomes especially useful when it comes to understanding how computers internally store numeric data.

The two most common methods of converting decimal number system to binary number system is via the division by 2 method or the subtraction method using powers of 2.

Division by 2 method

In this method, you repeatedly divide the decimal number by 2 and recording the remainders. The binary result is formed by reading the remainders from the bottom to the top.

Let’s solve an example

Convert 23 to binary:

  1. 23 ÷ 2 = 11, remainder → 1
  2. 11 ÷ 2 = 5, remainder → 1
  3. 5 ÷ 2 = 2, remainder → 1
  4. 2 ÷ 2 = 1, remainder → 0
  5. 1 ÷ 2 = 0, remainder → 1

The remainders would be read from bottom to top so, 10111

Subtracting powers of 2

This method starts with listing the powers of 2 from largest to smallest, stopping before you exceed the number. We then subtract the largest power of 2, then mark 1 in that position. Mark a 0 wherever the power of 2 cannot fit.

Let’s solve an example
Convert 19 to binary:

  1. Closest powers of 2:
    \(16 (2^4), 8 (2^3), 4 (2^2), 2 (2^1), 1 (2^0)\)
  2. 19 − 16 = 3 → write 1
  3. 8 is too big → write 0
  4. 4 is too big → write 0
  5. 2 fits → 3 − 2 = 1 → write 1
  6. 1 fits → 1 − 1 = 0 → write 1

Reading from top to bottom would give you, 10011.

Basic binary number system arithmetic operations

Now that we’ve understood how to convert binary into decimal, Let’s learn how to do some basic arithmetic operations. The rules are the exact same except much simpler because you are working with only two digits (0 and 1).

Let’s get into it starting off with addition.

Binary addition

Binary addition follows four simple rules:

ABA + B
000
011
101
1110 (0 with carry 1)

Example: Add 1010 + 1101

   1010

+  1101

——-

  10111

Explanation:

  • 0 + 1 = 1
  • 1 + 0 = 1
  • 0 + 1 = 1
  • 1 + 1 = 10 → write 0, carry 1
  • Final carry = 1 → add it to the front

Result: 10111 (which is 23 in decimal)

Binary subtraction

Binary subtraction also has simple rules:

ABA − B
000
101
110
011 (borrow 1)

Example: Subtract 1101 – 1010

   1101

−  1010

——–

    0011

Explanation:

  • 1 − 0 = 1
  • 0 − 1 → borrow → becomes 10 − 1 = 1
  • 1 − 0 = 1
  • 1 − 1 = 0

Result: 0011 (which is 3 in decimal)

Binary multiplication

Binary multiplication is similar to decimal multiplication but much simpler:

ABA × B
000
010
100
111

Example: Multiply 101 × 11

      101   (5)

   ×   11   (3)

   ——-

      101   (101 × 1)

+   1010    (101 × 1, shifted left)

———

    1111   (15 in decimal)

Result: 1111

Binary division

Binary division is like long division in decimal. You find how many times the divisor fits into the dividend and subtract repeatedly.

Divide 1101 ÷ 11

  • 1101 (13 in decimal) ÷ 11 (3 in decimal)
  • 3 fits into 13 four times with a remainder of 1

Result:

  • Quotient: 100 (4 in decimal)
  • Remainder: 1

Now that you’ve learned how to count, convert, and compute in binary, let’s learn about how binary is used practically.

The applications of binary

Understanding binary doesn’t just stop at the theoretical aspects, it bridges to real world applications. From storing data to executing instructions, binary is the language of machines

Data storage

Whether it’s text, image, audio, or videos, all data in a computer is stored as binary digits (bits). A bit is a single binary digit either 0 or 1. A byte is 8 bits which is often used to store a single character.

As a matter of fact, files, memory, and disk capacities are all measured in bytes. Some of the most common data representations are as follows:

  • 1 KB = 1,024 bytes
  • 1 MB = 1,024 KB
  • 1 GB = 1,024 MB

Computer processing

The Central Processing Unit (CPU) executes machine instructions in binary. For example, every command like “add,” “load,” or “jump” has a binary equivalent or representation.

These instructions will then be processed by the logic gates, which use binary input and output to perform operations.

Digital images, colours, and pixels

All images are made up of tiny units you might have heard of called pixels, each pixel’s colour is defined using a binary value.

A Red Greed Blue (RGB) colour might be stored as the following:

  • Red: 11111111 (255)
  • Green: 00000000 (0)
  • Blue: 00000000 (0)

This will result in pure red.

Networking and IP addresses

Every device that has the capability to connect to the internet has an IP address, which is just another binary number under the layers.

Let’s look at an example:

IPv4: 192.168.0.1 = 11000000.10101000.00000000.00000001 in binary

As you can see all IP addresses are basically a set of binary numbers made more readable in decimal. Routers and switches use binary to route data efficiently.

In conclusion, binary is not just something to be studied theoretically, it powers everything from the smartphones we use to the internet we access. Once you understand how it works, you’re one step closer to mastering computer science, programming, or electronics.

Leave a Comment
×