Understanding the conversion of Human Language to Binary format:

Shan
4 min readJul 5, 2024

--

We humans communicate through various languages like English, Hindi, Tamil, and so on. Similarly, computers have their own language called binary, which consists of 0’s and 1’s. Often, we hear that the data we type gets converted into a binary format that computers can understand, but we might not know how this conversion happens behind the scenes for various data types like numbers, characters, images, and videos. In this article, let’s explore how these different types of data we input into computers get converted into binary format.

Converting Numbers to Binary:

There are 2 ways of converting the number to binary format:

Approach1: using power of 2

Integers are converted to binary using a straightforward method called positional notation, where each bit represents a power of 2.

This method involves breaking down the number into sums of powers of 2. Here’s how it works:

  1. Identify the largest power of 2 less than or equal to the number.
  2. Subtract that power of 2 from the number.
  3. Repeat the process with the remainder until you reach zero.

Example:

Convert 13 to Binary

Step-by-Step Explanation Using Powers of 2:

1.Find the highest power of 2 less than or equal to 13:

  • The highest power of 2 less than or equal to 13 is 2³ = 8.
  • Subtract 8 from 13 to get 13−8=5

2.Find the highest power of 2 less than or equal to 5:

  • The highest power of 2 less than or equal to 5 is 2²=4.
  • Subtract 4 from 5 to get 5−4=1.

3.Find the highest power of 2 less than or equal to 1:

  • The highest power of 2 less than or equal to 1 is 2⁰=1.
  • Subtract 1 from 1 to get 1−1=0.

Now, let’s express 13 as the sum of these powers of 2:

13 = 8 + 4 + 1 = 2³ + 2² + 2⁰

Binary Representation:

Each of these powers of 2 can be represented in binary:

  • 2³ = 8corresponds to 1000
  • 2² = 4corresponds to 0100
  • 2⁰ = 1 corresponds to 0001
The binary representation of 13 is 1101<sub>2</sub>.

Approach 2: Taking Remainders

This method involves repeatedly dividing the number by 2 and recording the remainders. Here’s how it works:

  1. Divide the number by 2 and record the remainder.
  2. Use the quotient from the previous step as the new number.
  3. Repeat until the quotient is zero.
  4. The binary number is the remainders read from bottom to top.

Example:

Convert 13 to Binary

  1. 13 ÷ 2 = 6 remainder 1
  2. 6 ÷ 2 = 3 remainder 0
  3. 3 ÷ 2 = 1 remainder 1
  4. 1 ÷ 2 = 0 remainder 1

Read remainders from bottom to top: 1101.

Characters

Characters are typically converted to binary using character sets and character encoding.

Character sets: It is a predefined list where each character is represented by a number. Popular character sets are ASCII,Unicode.

Character Encoding: It says how the character’s number should represent in binary format.eg: “utf-8”.

Example: Converting the character ‘A’:

  • ASCII code for ‘A’ is 65.
  • 65 = 01000001.

Image

Images are converted to binary through formats like BMP, JPEG, PNG, etc. Each pixel is represented by bits depending on the color depth.

Example:

  • In a grayscale image with 8-bit depth, each pixel is represented by an 8-bit binary number indicating the intensity.
  • For a color image using RGB with 24-bit color, each pixel has 3 components (Red, Green, Blue), each 8 bits.
A pixel with color (255, 0, 0) (pure red) in binary: 
11111111<sub>2</sub>00000000<sub>2</sub>00000000<sub>2</sub>

Video

Videos are sequences of images (frames) with added audio. The binary representation includes the encoding of each frame and the audio track.

Example:

  • A video format like MP4 compresses the video and audio streams.
  • Each frame is a binary-encoded image.
  • Audio is often encoded using standards like MP3 or AAC.

Frame Example:

  • A single frame of a video might be encoded similar to an image, with additional metadata for synchronization.

Detailed Step-by-Step Example

Let’s take a step-by-step example of converting a simple text and an image.

Text Example: “Hi!”

  1. ‘H’ -> ASCII 72 -> 01001000
  2. ‘i’ -> ASCII 105 -> 01101001
  3. ‘!’ -> ASCII 33 -> 00100001
So, "Hi!" in binary: 
010010000110100100100001

Image Example: 2x2 Grayscale Image

[255, 128]
[64, 0]

Each pixel in 8-bit grayscale:

  • 255 -> 11111111
  • 128 -> 10000000
  • 64 -> 01000000
  • 0 -> 00000000

So, the image in binary: 11111111100000000100000000000000.

Summary:

  • Integers use direct binary representation of powers of 2 or by keep traacking of the remainder.
  • Characters use encoding schemes like ASCII and Unicode.
  • Images use formats that encode pixel values in binary.
  • Videos combine image frames and audio, compressed in formats like MP4.

By understanding these conversion we can have better understanding on how computers interpret and process various types of data, bridging the gap between human language and machine language.While high-level tasks are managed by compilers and interpreters, the fundamental representation of data in binary is crucial for efficient computing.

--

--

Shan

Just a random girl sharing her learnings thorugh blog and gaining knowledge from others.