Understanding Binary, ASCII, and Bitwise Logic

How Computers Understand 1s and 0s: Binary System, Character Encoding, and Logical Operations

We’ve all heard that computers work with 1s and 0s, but what does that actually mean? What do those 1s and 0s represent? How do letters turn into numbers? And how are these numbers manipulated?

That’s exactly what this post is all about.

What Is Binary and Why 1s and 0s?

Because computers work with electricity, they can only recognize two states:

  • Power on (1)
  • Power off (0)

That’s why computers use the binary system, which is based on only two digits: 0 and 1.

Binary is a base-2 number system, where each digit represents a power of 2. For example, the binary number 1011 means:

1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11

So 1011₂ = 11₁₀

What Are Bits and Bytes?

  • A bit is a single binary digit: either 0 or 1.
  • A byte is 8 bits. For example: 01001101

Since 8 bits can represent 2⁸ = 256 values, a single byte can encode any number between 0 and 255.
That’s why many things in computers — especially characters — are represented using a single byte.

How Do Computers Understand Letters?

This was one of my biggest early questions:
“How does a computer know that I typed the letter ‘A’?”

The answer: Every character is represented by a number, and that number is stored as binary.

This is typically done using something called the ASCII standard.

CharacterASCIIBinary (8-bit)
A6501000001
B6601000010
a9701100001
(space)3200100000

So when you type the letter “A”, your computer sees the number 65, and stores it in binary as 01000001.

What About Non-English Characters?

ASCII is limited to basic English characters. To support accented letters (like ç, ñ), other languages, and emoji, we use Unicode, particularly the UTF-8 encoding.

Examples:

  • ç → Unicode: U+00E7 → UTF-8: 2 bytes
  • 😊 → Unicode: U+1F60A → UTF-8: 4 bytes

UTF-8 is flexible:

  • English letters = 1 byte
  • Special characters = 2–4 bytes

Logical Operations: AND, OR, XOR, NOT

Once characters are turned into numbers and then into binary, we can do bit-level operations on them.
These are called logical operations, and they’re at the core of everything from programming to hardware design.

AND (&) – Logical AND

Returns 1 only if both bits are 1

ABA & B
111
100
010
000
11001100
10101010
---------
10001000

Real-life use: Masking — to extract specific bits, like network addresses in IP calculations.

OR (|) – Logical OR

Returns 1 if at least one bit is 1

11001100
10101010
---------
11101110

Use case: To “set” certain bits to 1 — useful when enabling options or permissions.

XOR (^) – Exclusive OR

Returns 1 if the bits are different, 0 if they’re the same

11001100
10101010
---------
01100110

Use cases:

  • Encryption (very basic: message ^ key = ciphertext)
  • Swapping two variables without a temp
  • Error detection in data transmission

NOT (~) – Bitwise NOT

Flips every bit:

  • 1 becomes 0
  • 0 becomes 1

However, in many programming languages (like Python), the NOT operator also affects the sign bit, so we often mask the result with & 0xFF to stay within 8 bits.

a = 0b00001111
not_a = ~a & 0xFF # → 11110000

Real-World Examples

XOR Encryption Example
message = 0b01010101
key = 0b00110011

cipher = message ^ key # encrypted data
original = cipher ^ key # decrypted again
IP Subnetting Using AND

To find the network address of an IP, we use bitwise AND between the IP and its subnet mask.

IP:        192.168.1.10 → 11000000.10101000.00000001.00001010
Subnet: 255.255.255.0 → 11111111.11111111.11111111.00000000
---------------------------------------------------------------
Network: → 11000000.10101000.00000001.00000000
→ 192.168.1.0

When I first realized that “a letter becomes a number, then becomes binary, and then logic operations are applied,” it really helped things click into place.

It’s strange (and cool) to think that a character is just voltage on wires, represented by eight 1s and 0s.

What surprised me most is that everything, from:

  • encryption and security,
  • to how your computer connects to a Wi-Fi network,
  • to how memory is optimized,

is all built on these tiny bitwise manipulations.

Leave a Reply

Your email address will not be published. Required fields are marked *