Data Representation
Data Representation
Computers store and process data as numbers, specifically in binary. Since modern computer architecture relies on transistors which are either On (1) or Off (0)
A light switch has two states, on and off. Computers work the same way with 1s and 0s.
The Representation of Integers in Binary
Binary
Binary is a base-2 number system, using only two digits: 0 and 1. Each digit in a binary number is called a bit (short for binary digit).
Place Value in Binary
- Each bit position represents a power of 2, starting from $2^0$ at the rightmost bit and increasing to the left.
- Example: The binary number $1011_2$ can be broken down as follows:
| Bit | 0 | 0 | 0 | 0 | 1 | 0 | 1 | 1 |
|---|---|---|---|---|---|---|---|---|
| Place Value | $$2^7$$ | $$2^6$$ | $$2^5$$ | $$2^4$$ | $$2^3$$ | $$2^2$$ | $$2^1$$ | $$2^0$$ |
| Place Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Decimal Value | 0 | 0 | 0 | 0 | 8 | 0 | 2 | 1 |
Calculation: $1 \times 8 + 0 \times 4 + 1 \times 2 + 1 \times 1 = 11_{10}$Note
Binary is the most compact representation for computers, as it directly aligns with their hardware, which uses transistors operating in two states.
Converting Binary to Decimal
- Identify the Place Values: Each bit represents a power of 2.
- Multiply Each Bit by Its Place Value: For each 1 in the binary number, multiply it by the corresponding power of 2.
- Add the Products: Sum the results to get the decimal value.
Convert $1011_2$ to decimal.
Solution
- Place Values: $2^3, 2^2, 2^1, 2^0$
- Multiplication: $1 \times 8 + 0 \times 4 + 1 \times 2 + 1 \times 1$
- Sum: $8 + 0 + 2 + 1 = 11_{10}$
- When converting binary to decimal, it can be helpful to read the binary number from right to left, aligning each bit with its corresponding power of 2.
- Draw it out in a table if necessary
| Place Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
|---|---|---|---|---|---|---|---|---|
| Binary | 1 | 0 | 1 | 1 | 0 | 0 | 1 | 1 |
| Calculation | (128 x 1) | + 0 | + (32 x 1) | + (16 x 1) | + 0 | + 0 | + (2 x 1) | + (1 x 1) |
Converting Decimal to Binary
- Divide the Decimal Number by 2: Record the remainder (0 or 1).
- Repeat: Continue dividing the quotient by 2 until it reaches 0.
- Write the Remainders in Reverse Order: This forms the binary number.
Convert $13_{10}$ to binary.
Solution
- $13 \div 2 = 6$ R1
- $6 \div 2 = 3$ R0
- $3 \div 2 = 1$ R1
- $1 \div 2 = 0$ R1
Binary: $1101_2$
Method 2: Subtraction Method
- Start from largest power of 2 that fits
- Subtract it and write a 1
- Write 0s for any place values that don’t fit
Convert denary value 13 to binary
Solution
- 8 fits → 13 - 8 = 5 (so 1 in the 8 column)
- 4 fits → 5 - 4 = 1 (so 1 in the 4 column)
- 2 doesn’t fit (so 0 in the 2 column)
- 1 fits → 1 - 1 = 0 (so 1 in the 1 column)
- Binary = 1101, or 00001101 (8-bit)
- Binary numbers are often represented in 8 bits (a byte).
- If the binary number has fewer than 8 bits, pad with zeros on the left.
The Representation of Integers in Hexadecimal
Hexadecimal
Hexadecimal is a base-16 number system, using 16 digits: 0–9 and A–F (where A = 10, B = 11, ..., F = 15).
Why Use Hexadecimal?
- Human-Readable: More compact than binary, making it easier to read and write.
- Efficient for Computers: Each hexadecimal digit corresponds to 4 bits (a nibble), simplifying conversion between binary and hexadecimal.
Converting Hexadecimal to Decimal
- Identify the Place Values: Each digit represents a power of 16.
- Convert Letters to Decimal: A = 10, B = 11, ..., F = 15.