Binary and Data Representation
Understanding Binary
Binary is the fundamental language of computers, using only two digits (0 and 1) to represent all data. Each binary digit (bit) represents a state that can be either on (1) or off (0).
Key Binary Concepts
- Binary digits (bits) - The smallest unit of data (0 or 1)
- Bytes - 8 bits grouped together
- Binary patterns - Sequences of bits that represent data
- Base-2 number system - Powers of 2 (1, 2, 4, 8, 16, etc.)
Binary Number System
Converting Between Binary and Decimal
Binary | Calculation | Decimal |
---|---|---|
0001 | 0×8 + 0×4 + 0×2 + 1×1 | 1 |
0101 | 0×8 + 1×4 + 0×2 + 1×1 | 5 |
1000 | 1×8 + 0×4 + 0×2 + 0×1 | 8 |
1111 | 1×8 + 1×4 + 1×2 + 1×1 | 15 |
Decimal to Binary Conversion Steps:
- Divide the number by 2
- Keep track of remainders (0 or 1)
- Continue dividing quotient by 2
- Read remainders from bottom to top
13 ÷ 2 = 6 remainder 1
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Reading from bottom up: 1101
Data Representation
Text Representation (ASCII)
ASCII (American Standard Code for Information Interchange) uses 7 bits to represent characters.
Character | ASCII (Decimal) | Binary |
---|---|---|
A | 65 | 1000001 |
B | 66 | 1000010 |
a | 97 | 1100001 |
1 | 49 | 0110001 |
Color Representation (RGB)
Colors are represented using three bytes, one each for Red, Green, and Blue values (0-255).
Color | Red | Green | Blue | Hex Code |
---|---|---|---|---|
Red | 255 | 0 | 0 | #FF0000 |
Purple | 128 | 0 | 128 | #800080 |
White | 255 | 255 | 255 | #FFFFFF |
Image Representation
Digital images are grids of pixels, where each pixel is represented by color values.
Image Storage Components:
- Resolution (width × height in pixels)
- Color depth (bits per pixel)
- Compression method (lossy or lossless)
- File format (JPEG, PNG, GIF, etc.)
Data Storage Units
Unit | Size | Example Usage |
---|---|---|
Bit (b) | 1 or 0 | Single binary digit |
Byte (B) | 8 bits | Single character |
Kilobyte (KB) | 1,024 bytes | Short text document |
Megabyte (MB) | 1,024 KB | Digital photo |
Gigabyte (GB) | 1,024 MB | Movie file |
Terabyte (TB) | 1,024 GB | Large database |
Data Compression
Lossless Compression
Reduces file size while preserving all original data. Commonly used for text and program files.
Original: AAAAAABBBCC
Compressed: 6A3B2C
(Saves space while maintaining all information)
Lossy Compression
Reduces file size by removing some data, typically used for media files where small quality loss is acceptable.
Common Lossy Formats:
- JPEG - Images
- MP3 - Audio
- MP4 - Video
Error Detection and Correction
Parity Bits
A simple error detection method that adds an extra bit to make the total number of 1s even or odd.
Data | Count of 1s | Even Parity Bit | Result |
---|---|---|---|
1101 | 3 | 1 | 11011 |
1001 | 2 | 0 | 10010 |
Checksum
A more advanced error detection method that creates a value based on the data being transmitted.
Data: 10110
Checksum calculation: 1+0+1+1+0 = 3
Transmitted: 10110 (data) + 11 (checksum in binary)
Practice Problems
Problem 1: Binary Conversion
Convert the decimal number 25 to binary.
Solution
25 ÷ 2 = 12 remainder 1
12 ÷ 2 = 6 remainder 0
6 ÷ 2 = 3 remainder 0
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
Binary: 11001
Problem 2: Data Storage
Calculate the storage required for a 1920×1080 image with 24-bit color depth.
Solution
Pixels: 1920 × 1080 = 2,073,600
Bits per pixel: 24
Total bits: 2,073,600 × 24 = 49,766,400
Total bytes: 49,766,400 ÷ 8 = 6,220,800
Total MB: 6,220,800 ÷ 1,024,000 ≈ 6.07 MB
Problem 3: Error Detection
Add an even parity bit to the binary number 1011001.
Solution
Data: 1011001
Count of 1s: 4 (even)
Even parity bit needed: 0
Result: 10110010