Binary is the foundation of all modern computing systems. Every program you write, every image you see, every database record, and every network packet ultimately resolves to binary data—a sequence of 0s and 1s.
1. What Is Binary?
Binary is a base-2 number system that uses only two digits:
0 and 1
| System | Base | Digits |
|---|---|---|
| Decimal | 10 | 0–9 |
| Binary | 2 | 0–1 |
| Octal | 8 | 0–7 |
| Hexadecimal | 16 | 0–9, A–F |
Computers use binary because electronic circuits have two stable states:
-
Low voltage (OFF) →
0 -
High voltage (ON) →
1
2. Binary at the Hardware Level (Physical Architecture)
2.1 Transistors
A transistor acts as a switch:
| State | Voltage | Binary |
|---|---|---|
| OFF | Low | 0 |
| ON | High | 1 |
Modern CPUs contain billions of transistors, each storing or manipulating binary data.
2.2 Logic Gates (Binary Logic)
Binary data is processed using logic gates.
| Gate | Operation | Truth Table | |
|---|---|---|---|
| AND |
1 if both are 1
|
1 & 1 = 1 |
|
| OR |
1 if any is 1
|
`1 | 0 = 1` |
| NOT | Inverts | !1 = 0 |
|
| XOR | Different → 1
|
1 ^ 0 = 1 |
Example:
A = 1
B = 0
A AND B = 0
A OR B = 1
A XOR B = 1
These gates form adders, multiplexers, registers, and ALUs.
3. Binary Data Units
| Unit | Size |
|---|---|
| Bit | 1 binary digit |
| Nibble | 4 bits |
| Byte | 8 bits |
| Word | CPU-dependent (32 or 64 bits) |
Example byte:
10101100
4. Binary Number Representation
4.1 Positional Value (Base-2)
Binary digits represent powers of 2:
Binary: 1 0 1 1
Index: 3 2 1 0
Value: 8 0 2 1
Result: 11 (decimal)
4.2 Decimal to Binary Conversion
Example: Convert 13 → Binary
13 / 2 = 6 remainder 1
6 / 2 = 3 remainder 0
3 / 2 = 1 remainder 1
1 / 2 = 0 remainder 1
Binary = 1101
4.3 Binary to Decimal
Example:
10101 = (1×16) + (0×8) + (1×4) + (0×2) + (1×1)
= 21
5. Signed Binary Numbers
5.1 Unsigned Binary
Only positive values.
5.2 Signed Binary (Two’s Complement)
Most systems use Two’s Complement.
Steps to represent -5 in 8 bits:
-
5→00000101 - Invert →
11111010 - Add 1 →
11111011
Range:
8-bit signed → -128 to +127
6. Binary Arithmetic
6.1 Binary Addition
1011
+ 0110
------
10001
Rules:
0+0=01+0=1-
1+1=10(carry)
6.2 Binary Subtraction
Uses two’s complement internally.
6.3 Binary Multiplication
Shift-and-add method.
101 × 11
= 101
+1010
-----
1111
7. Binary in CPU Architecture
7.1 Registers
Registers store binary values:
RAX = 0000000000001010
7.2 ALU (Arithmetic Logic Unit)
ALU performs:
- Binary arithmetic
- Bitwise logic
- Comparisons
7.3 Instruction Encoding
Machine code:
10101010 00001010
Assembly:
MOV AX, 10
8. Binary Memory Representation
8.1 RAM
Memory is a sequence of bytes:
Address Data
0x1000 → 01010101
0x1001 → 11100010
8.2 Endianness
| Type | Order |
|---|---|
| Little Endian | Least byte first |
| Big Endian | Most byte first |
Example (0x12345678):
Little → 78 56 34 12
Big → 12 34 56 78
9. Binary Data Types
9.1 Integers
int x = 5; // 00000101
9.2 Floating Point (IEEE-754)
Structure:
[ Sign ][ Exponent ][ Mantissa ]
32-bit float:
- 1 sign bit
- 8 exponent bits
- 23 mantissa bits
10. Bitwise Operations (Binary Syntax)
| Operator | Meaning | |
|---|---|---|
& |
AND | |
| ` | ` | OR |
^ |
XOR | |
~ |
NOT | |
<< |
Left shift | |
>> |
Right shift |
Example in C:
int a = 5; // 0101
int b = 3; // 0011
int c = a & b; // 0001
11. Binary Encodings
11.1 ASCII
'A' → 65 → 01000001
11.2 Unicode / UTF-8
Supports all languages.
'€' → 11100010 10000010 10101100
12. Binary Files and Storage
All files are binary:
- Images
- Videos
- PDFs
- Executables
Example file header:
PDF → 25 50 44 46
13. Binary in Networking
Network packets are binary streams.
Example TCP header fields:
Source Port → 16 bits
Destination → 16 bits
Flags → 6 bits
14. Binary Compression
Compression algorithms manipulate bits:
- Huffman Encoding
- LZ77
- DEFLATE
15. Binary Security & Cryptography
Encryption operates on binary blocks:
- AES → 128-bit blocks
- RSA → binary exponentiation
- Hashes → bit mixing
16. Binary in Programming Languages
Python
x = 10
print(bin(x)) # 0b1010
JavaScript
let x = 5;
console.log(x.toString(2)); // "101"
C++
int x = 5;
std::bitset<8> b(x); // 00000101
17. Why Binary Is Irreplaceable
Binary provides:
- Electrical stability
- Noise tolerance
- Logical clarity
- Hardware simplicity
- Universal abstraction
No modern digital system operates without binary.
18. Summary
Binary is:
- The lowest-level language of computers
- The bridge between physics and software
- The foundation of CPU, memory, networking, files, and security
Understanding binary deeply makes you:
- A better programmer
- A stronger system designer
- A more confident low-level engineer
Final Thought
Every abstraction eventually collapses into binary.
If you understand binary, you understand computing at its core.
Top comments (0)