DEV Community

Shankar L
Shankar L

Posted on

Binary Numbers Explained Without Confusion

Why should you care?

Every piece of data inside a computer is stored using binary. Whether it is a photo, a video, a game, a document, or the program you wrote yesterday, everything eventually becomes a sequence of 0s and 1s.

Understanding binary is one of the first steps toward learning how computers really work. It also makes topics like memory, networking, data structures, operating systems, and computer architecture much easier to understand.

If you have ever wondered why computers use only two numbers instead of ten, this article is for you.


The Problem

Humans naturally count using decimal numbers.

0 1 2 3 4 5 6 7 8 9
Enter fullscreen mode Exit fullscreen mode

Computers, however, use only:

0 1
Enter fullscreen mode Exit fullscreen mode

This raises a few obvious questions.

  • Why only two numbers?
  • How can a computer represent large numbers with only 0 and 1?
  • How can letters, images, music, and videos all be represented using binary?

The answer starts with understanding how computer hardware works.


The Concept

A computer is built from billions of tiny electronic switches called transistors.

Each transistor has only two stable states.

OFF
ON
Enter fullscreen mode Exit fullscreen mode

We represent these states as:

OFF = 0
ON  = 1
Enter fullscreen mode Exit fullscreen mode

Because hardware naturally works with two states, computers use the Binary Number System, also known as Base 2.

Unlike our decimal system, which has ten digits, binary has only two.


Simple Explanation

Think of binary as another way of counting.

Decimal uses powers of 10.

10³ 10² 10¹ 10⁰
Enter fullscreen mode Exit fullscreen mode

Binary uses powers of 2.

2⁷ 2⁶ 2⁵ 2⁴ 2³ 2² 2¹ 2⁰
Enter fullscreen mode Exit fullscreen mode

Every position represents a power of two.

For example:

Binary: 1011

Position: 2³ 2² 2¹ 2⁰
Values:     8  4  2  1
Digits:     1  0  1  1
Enter fullscreen mode Exit fullscreen mode

Now multiply each digit by its value.

1 × 8 = 8
0 × 4 = 0
1 × 2 = 2
1 × 1 = 1

Total = 11
Enter fullscreen mode Exit fullscreen mode

So:

1011₂ = 11₁₀
Enter fullscreen mode Exit fullscreen mode

The small numbers indicate the number system being used.


Real world Analogy

Imagine four light switches.

Each switch can only be:

OFF
ON
Enter fullscreen mode Exit fullscreen mode

Suppose each switch has a value.

8 4 2 1
Enter fullscreen mode Exit fullscreen mode

Now turn on only the switches worth 8, 2, and 1.

ON  OFF  ON  ON

1    0    1    1
Enter fullscreen mode Exit fullscreen mode

The total becomes:

8 + 2 + 1 = 11
Enter fullscreen mode Exit fullscreen mode

This is exactly how binary numbers work.

Every bit is simply another switch.


Code Example

Java makes it easy to work with binary numbers.

public class Main {
    public static void main(String[] args) {

        int decimal = 13;

        System.out.println(Integer.toBinaryString(decimal));
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:

1101
Enter fullscreen mode Exit fullscreen mode

To convert a binary string back into a decimal number:

public class Main {
    public static void main(String[] args) {

        String binary = "1101";

        int decimal = Integer.parseInt(binary, 2);

        System.out.println(decimal);
    }
}
Enter fullscreen mode Exit fullscreen mode

Output:

13
Enter fullscreen mode Exit fullscreen mode

Common Mistakes

Mistake 1

Reading binary like a decimal number.

For example:

1010
Enter fullscreen mode Exit fullscreen mode

This is not one thousand and ten.

It represents:

8 + 2 = 10
Enter fullscreen mode Exit fullscreen mode

Mistake 2

Ignoring place values.

Each position in binary represents a power of two, not a power of ten.

128 64 32 16 8 4 2 1
Enter fullscreen mode Exit fullscreen mode

Always start counting from the rightmost bit.


Mistake 3

Thinking more digits always mean a larger decimal number.

Compare:

1111 = 15

10000 = 16
Enter fullscreen mode Exit fullscreen mode

Adding one more bit increases the range dramatically.


Mistake 4

Confusing bits and bytes.

A bit is a single binary digit.

0
Enter fullscreen mode Exit fullscreen mode

or

1
Enter fullscreen mode Exit fullscreen mode

A byte contains 8 bits.

Example:

11001010
Enter fullscreen mode Exit fullscreen mode

Advanced Notes

Binary Prefixes

Computers group binary digits into larger units.

Unit Size
1 Bit 0 or 1
1 Nibble 4 Bits
1 Byte 8 Bits
1 Kilobyte 1024 Bytes
1 Megabyte 1024 KB
1 Gigabyte 1024 MB

Why 8 Bits?

Eight bits can represent:

2⁸ = 256
Enter fullscreen mode Exit fullscreen mode

different values.

That is enough to store characters, colours, and many small numbers efficiently.


Signed Numbers

Computers also represent negative numbers.

Most modern systems use Two's Complement, allowing positive and negative numbers to be stored efficiently using the same binary representation.

This is a topic worth learning once you are comfortable with basic binary.


Binary Beyond Numbers

Binary is not just used for integers.

Everything eventually becomes binary.

For example:

  • Characters use ASCII or Unicode.
  • Images store colour values as binary.
  • Audio stores sound samples as binary.
  • Videos are sequences of binary encoded frames.
  • Programs themselves are binary instructions executed by the CPU.

Binary is the universal language of computers.


Summary

Binary may look unfamiliar at first, but it is simply another number system.

Instead of using ten digits, it uses only two.

Decimal
0 1 2 3 4 5 6 7 8 9

Binary
0 1
Enter fullscreen mode Exit fullscreen mode

Each binary digit represents a power of two.

128 64 32 16 8 4 2 1
Enter fullscreen mode Exit fullscreen mode

Understanding binary helps explain:

  • How computers store numbers.
  • How memory works.
  • How processors execute instructions.
  • How files and programs are represented internally.

Master binary once, and many advanced computer science topics become much easier to understand.


Topics to explore next

  • Decimal to Binary Conversion
  • Binary to Decimal Conversion
  • Hexadecimal Numbers
  • Octal Number System
  • Bits vs Bytes
  • ASCII and Unicode
  • Two's Complement
  • Bitwise Operators

Top comments (0)