Computer Science ยท Chapter 7
Number System and Boolean Logic in short
Computers are built from switches that are either on or off, so at the hardware level everything is binary, but people usually find it easier to talk in decimal, octal, or hexadecimal and convert between them.
| System | Base | Digits | Example |
|---|---|---|---|
| Decimal | 10 | 0-9 | |
| Binary | 2 | 0, 1 (1 = ON/high voltage, 0 = OFF/low voltage) | |
| Octal | 8 | 0-7, a shorthand for grouping binary in threes | |
| Hexadecimal | 16 | 0-9, A-F (A=10 ... F=15), used in memory addressing |
Each digit's position carries a place value equal to the base raised to that position (counting the rightmost position as 0), and this is what makes conversion between bases possible.
Divide repeatedly by the target base and collect the remainders; the first remainder is the least significant digit, so remainders are read bottom to top.
Converting to binary:
Reading remainders last-to-first gives . The same method applies for octal (divide by 8) and hex (divide by 16): and .
Multiply each digit by its place value and add.
(E = 14, D = 13 in the last example.)