1.0 The Language of Computers: From Bits to Numbers
At its core, a computer doesn’t understand words, images, or sounds. It understands a much simpler language based on two electrical states: ON and OFF. In the digital world, we represent these states with the numbers 1 and 0. Everything a computer does, from complex calculations to displaying this text, is built upon this simple binary foundation.
1.1 Speaking in Binary
The most fundamental unit of computer storage is the bit, which can hold a single value of either 1 (ON) or 0 (OFF). To represent more complex information, computers group bits together. A group of 8 bits is called a byte.
The binary number system works on a principle called positional notation, just like our familiar decimal system (base-10). However, in binary (base-2), the value of each position is a power of 2.
The table below shows the positional values for a single 8-bit byte:
| Position Value | 128 | 64 | 32 | 16 | 8 | 4 | 2 | 1 |
| Power of Base 2 | 2⁷ | 2⁶ | 2⁵ | 2⁴ | 2³ | 2² | 2¹ | 2⁰ |
| Bit Number | 7 | 6 | 5 | 4 | 3 | 2 | 1 | 0 |
To find the decimal value of a binary number, you simply add up the position values for every bit that is a 1. For example, the binary number 11111111 (where all bits are “ON”) represents the decimal value 255:
128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255
1.2 Hexadecimal: A Programmer’s Shorthand
Binary numbers can become very long and difficult for humans to read. To solve this, programmers use the hexadecimal number system (base-16) to abbreviate lengthy binary strings. Hexadecimal uses digits 0-9 and the letters A-F to represent decimal values 0-15.
| Decimal | Binary | Hexadecimal |
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| 10 | 1010 | A |
| 11 | 1011 | B |
| 12 | 1100 | C |
| 13 | 1101 | D |
| 14 | 1110 | E |
| 15 | 1111 | F |
Converting between binary and hexadecimal is straightforward because 16 is a power of 2 (2⁴). This means that every group of 4 bits corresponds to exactly one hexadecimal digit.
- Binary to Hexadecimal: Break the binary string into groups of 4 bits (from right to left) and replace each group with its hex equivalent.
- 1000 1100 1101 0001 becomes 8CD1.
- Hexadecimal to Binary: Replace each hex digit with its 4-bit binary equivalent.
- FAD8 becomes 1111 1010 1101 1000.
1.3 Handling Negative Numbers: The Two’s Complement Trick
Computers must also represent negative numbers. The most common method for this is two’s complement notation. To find the negative representation of a binary number, you follow two simple steps:
- Reverse the bits: Change every 1 to a 0 and every 0 to a 1.
- Add 1 to the result.
Let’s convert the decimal number 53 to -53 using an 8-bit representation. The binary for 53 is 00110101.
- Step 1 (Reverse bits): The reverse of 00110101 is 11001010.
- Step 2 (Add 1): We add 1 to the reversed bits.
- Therefore, 11001011 is the two’s complement representation of -53.
Now that we understand how data is represented in binary, let’s explore where this information is stored.