Binary in Computing
How Computers Think in 1s e 0s
Understand BinaryEvery photo, video, program, e website ultimately exists as patterns di 1s e 0s. Binary isn't just another number system—it's il foundation di all digital technology. Comprendere binary reveals how computers work at their most fundamental level.
Bits e Byte
Il Bit
- Smallest unit di data
- Single binary digit: 0 o 1
- "Binary digit" shortened un "bit"
- Can represent two states (yes/no, on/off, true/false)
Il Byte
- 8 bits grouped together
- Can represent 2⁸ = 256 different values (0-255)
- Standard unit per character storage
- Foundation per larger units (KB, MB, GB)
Larger Unita
| Unita | Size | Values |
|---|---|---|
| Byte | 8 bits | 256 |
| Word (16-bit) | 2 byte | 65,536 |
| Double word (32-bit) | 4 byte | ~4.3 billion |
| Quad word (64-bit) | 8 byte | ~18.4 quintillion |
How Data Is Represented
Text (Characters)
- ASCII: 7 bits, 128 characters
- Extended ASCII: 8 bits, 256 characters
- Unicode (UTF-8): Variable length, millions di characters
Esempio: 'A' = 01000001 (65 in decimal)
Numbers
- Integers: Direct binary representation
- Negative numbers: Two's complement
- Decimals: Floating-point (IEEE 754)
Images
- Pixels represented as numbers
- RGB: 3 byte per pixel (8 bits each per Red, Green, Blue)
- 1920×1080 image ≈ 6.2 million byte uncompressed
Audio
- Sound waves sampled as numbers
- CD quality: 16-bit samples, 44,100 times per secondo
Binary Arithmetic
Addition
Same as decimal, but carry at 2:
- 0 + 0 = 0
- 0 + 1 = 1
- 1 + 0 = 1
- 1 + 1 = 10 (0, carry 1)
- 1 + 1 + 1 = 11 (1, carry 1)
Esempio: 1011 + 1101
1011 + 1101 ------ 11000
= 11 + 13 = 24 ✓
Logic Gates
Hardware implements binary operations through logic gates:
Basic Gates
| Gate | Function | Truth |
|---|---|---|
| AND | Both inputs deve be 1 | 1 AND 1 = 1 |
| OR | At least one input e 1 | 1 OR 0 = 1 |
| NOT | Inverts input | NOT 1 = 0 |
| XOR | Exactly one input e 1 | 1 XOR 1 = 0 |
| NAND | NOT AND | 1 NAND 1 = 0 |
Complex operations (addition, comparison) sono built da combinations di these simple gates.
Signed Numbers: Two's Complement
How computers represent negative numbers:
Method
- Invert all bits
- Add 1
Esempio: -5 in 8-bit
- 5 = 00000101
- Invert: 11111010
- Add 1: 11111011
- -5 = 11111011
Perche Two's Complement?
- Addition works naturally (no special cases)
- One representation per zero
- Easy un implement in hardware
Bitwise Operations in Programming
Programming languages provide operators per bit manipulation:
Comuni Operations
- AND (&): Mask certain bits
- OR (|): Set certain bits
- XOR (^): Toggle bits, encryption
- NOT (~): Invert all bits
- Left shift (<<): Multiply da 2ⁿ
- Right shift (>>): Divide da 2ⁿ
Esempio: Check if number e even
n & 1 == 0 means n e even
(Last bit determines odd/even)
Binary in Modern Computing
Memory Addresses
- 32-bit: Can address 2³² = 4 GB
- 64-bit: Can address 2⁶⁴ = 16 exabytes
Network Addresses
- IPv4: 32 bits (e.g., 192.168.1.1)
- IPv6: 128 bits
File Sizes
- All files sono sequences di byte
- File type determined da content/structure
Encryption
- AES uses 128, 192, o 256-bit keys
- SHA-256 produces 256-bit hashes
Conclusione
Binary e il language di all digital systems because electronic components naturally hanno two states. Every piece di digital data—text, images, audio, video, programs—e ultimately represented as patterns di bits. Comprendere binary illuminates how computers work: da il logic gates performing operations un il byte storing characters un il bits flying across networks. While we rarely interact con binary directly, it underlies everything in il digital world.