Computer Science · Chapter 7
Study notes aligned to the official NEB syllabus.
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 | $(789)_{10}$ |
| Binary | 2 | 0, 1 (1 = ON/high voltage, 0 = OFF/low voltage) | $(110)_2$ |
| Octal | 8 | 0-7, a shorthand for grouping binary in threes | $(1234)_8$ |
| Hexadecimal | 16 | 0-9, A-F (A=10 ... F=15), used in memory addressing | $(C01F)_{16}$ |
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 $(149)_{10}$ to binary:
$$ \begin{aligned} 149\div2 &= 74\ \text{r}\ 1 \ \quad 74\div2 &= 37\ \text{r}\ 0 \ \quad 37\div2 &= 18\ \text{r}\ 1 \ \quad 18\div2 &= 9\ \text{r}\ 0 \ 9\div2 &= 4\ \text{r}\ 1 \ \quad 4\div2 &= 2\ \text{r}\ 0 \ \quad 2\div2 &= 1\ \text{r}\ 0 \ \quad 1\div2 &= 0\ \text{r}\ 1 \end{aligned} $$
Reading remainders last-to-first gives $(149){10}=(10010101)2$. The same method applies for octal (divide by 8) and hex (divide by 16): $(804){10}=(1444)8$ and $(1600){10}=(640){16}$.
Multiply each digit by its place value and add.
$$ \begin{aligned} (100100)2 &= 1{\cdot}2^5+0{\cdot}2^4+0{\cdot}2^3+1{\cdot}2^2+0{\cdot}2^1+0{\cdot}2^0 \ &= 32+4 \ &= (36){10} \ (2040)8 &= 2{\cdot}8^3+0{\cdot}8^2+4{\cdot}8^1+0{\cdot}8^0 \ &= 1024+32 \ &= (1056){10} \ (1E0D){16} &= 1{\cdot}16^3+14{\cdot}16^2+0{\cdot}16^1+13{\cdot}16^0 \ &= 4096+3584+13 \ &= (7693){10} \end{aligned} $$
(E = 14, D = 13 in the last example.)
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.)