back

Introduction to Binary

8 min read

In mathematics and computer science, binary is a number system that uses only two digits: 0 and 1. Computers rely on electrical signals that are on and off, corresponding to the binary digits 1 and 0. It serves as the foundation for how computers store, process information and transmitt data. In this article, we’ll explore the fundamental concepts of binary and how it’s used in computing.

Binary System (Base-2)

The binary system, aka base-2, is the primary language understood by computing systems. Unlike the decimal system (base-10) which uses ten digits (0-9), binary only uses two digits: 1 and 0. Each binary digit (bit) represents a power of 2. The value of a binary number is calculated by summing each bit and its corresponding power of 2. It is counting from the rightmost of the digit which represents 20, the next represents 21 and so on.

Let’s break down the binary number 1101 which represents the decimal number 13:

  • 1 * 23 = 8
  • 1 * 22 = 4
  • 1 * 21 = 2
  • 1 * 20 = 1

By adding these together gives: 8 + 4 + 2 + 1 = 13

Counting in Binary

To better understand binary, let’s see at how numbers are represented in this system compared to decimal. Each binary (bit) represents a power of 2, starting from the 20 on the rightmost. When counting in binary, we start from the rightmost digit (least significant bit) and move left when we need to increase the value. If the bit is 0, it is simple to change it to 1. However, if it is already 1, it turns into 0 and a 1 is carried over to the next bit on the left.

Here’s a table presenting the correlation between decimal numbers and their binary equivalents:

DecimalBinaryExplanation
000000 in binary
1000120 = 1
2001021 = 2
3001121 + 20 = 3
4010022 = 4
5010122 + 20 = 5
6011022 + 21 = 6
7011122 + 21 + 20 = 7
8100023 = 8
9100123 + 20 = 9
10101023 + 21 = 10

Binary Arithmetic

It follows simple rules similar to decimal arithmetic. Here are some basic operations:

Binary OperationResult
0 + 00
0 + 11
1 + 110 (carry 1)

Example of adding 101 and 110 is equivalent to decimal 5 + 6 = 11.

   101
+  110
------
  1011

In addition, it works similarly to decimal addition but it follows specific rules. When two bits are added, the result may generate a carry bit if the sum equals 2 (binary 10).

Example of subtracting 101 (5 in decimal) from 110 (6 in decimal).

   110
-  101
------
   001

In Substraction, it uses the borrow method. If a bit is substracted from a similar bit, a borrow is taken from the next higher bit.

Also, multiplication is similar to decimal multiplication. Each digit of the multiplier is multiplied by the entire multiplicand, and the results are added. Binary division follows the same principles as decimal division, using repeated subtraction.

Binary Logic In computing

Binary logic gates (AND, OR, NOT, XOR) form the backbone of digital ciruits. These gates take binary inputs and produce binary outputs based on logical operations. AND Gate outputs 1 only when both inputs are 1. OR Gate outputs 1 if at least one input is 1. NOT Gate outputs the inverse of the input. XOR Gate outputs 1 if exactly one input is 1.

Example of XOR Gate Operation

Input AInput BOutput (A XOR B)
000
011
101
110

Character Encoding: ASCII and Unicode

Binary also represents characters in computing. Letters in the alphabet are stored as numbers using ASCII and Unicode. The ASCII system maps binary codes to characters. It encodes 128 characters including English letters, digits and special symbols. Each character is represented by a 7-bit binary code. Uncode extends this mapping to include characters from many languages and symbols. It uses variable length enconding schemas such as UTF-8, UTF-16 and UTF-32.

Example of Binary Presentation of ‘A’ (ASCII 65)

Binary: 01000001, Decimal: 65

Understanding Bits, Bytes and Beyond

To grasp binary better, it is important to understand the basic concepts of Bits and Bytes. These tiny units form the foundation of all digit data.

The Mighty Bit

It is the smallest unit of digital information that has only 1 and 0. Think of it as a light switch, it can be either On or Off. It is the building block of all digital data such as text, images, sound and videos.

A Byte (8 Bits)

A bit is a group of 8 bits. It is a standard unit for data storage and communication in most computers. Eight bits can represent 256 different values from 11111111 to 00000000. The largest number of 8 bits represents 255 in decimal (not 256) but an 8-bit number can represent a total of 256 different values. The key point is that 0 is included as a value. The range of numbers that can be represented by 8 bits is from 0 to 255, which gives us 256 possible values in total. Let’s break down the binary number 11111111 :

  • 1 * 20 = 1
  • 1 * 21 = 2
  • 1 * 22 = 4
  • 1 * 23 = 8
  • 1 * 24 = 16
  • 1 * 25 = 32
  • 1 * 26 = 64
  • 1 * 27 = 128

By summing these values, we get: 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255

Since we start counting from 0, there are 256 possible numbers from 0 to 255. Bytes are commonly used to measure data storage. The larger units of bytes include kilobytes (KB), megabytes (MB), gigabytes (GB) and so on.

Summary of Units

UnitSize in BytesSize in Bits
1 Bit1 bit1 bit
1 Byte8 bits8 bits
1 KB210 = 1,024 * 1 Byte = 1,024 bytes8,192 bits
1 MB220 = 1,024 * 1 KB = 1,048,576 bytes8,388,608 bits
1 GB230 = 1,024 * 1 MB = 1,073,741,824 bytes8,589,934,592 bits
1 TB240 = 1,024 * 1 GB = 1,099,511,627,776 bytes8,796,093,022,208 bits
1 PB250 = 1,024 * 1 TB = 1,125,899,906,842,624 bytes9,007,199,254,740,992 bits
1 EB260 = 1,024 * 1 PB = 1,152,921,504,606,846,976 bytes9,223,372,036,854,775,808 bits

For example, a text file might be a few kilobytes. A high-quality photo might take up to a few megabytes. A movie could be several gigabytes. Hard disks and cloud storage are often measured in terabytes. Large data centers or companies like Google and Meta handle data in petabytes or exabytes.

Understanding binary is essential for grasping the inner workings of computers and digital systems. These bits and bytes form the foundation of building all digital information from simple text to complex multimedia applications. By exploring the binary system, we gain valuable insights into how technology empowers the modern digital world.