CSC 382 · Computer Architecture 1
Our notes
1 min readBases
| Decimal | Binary | Octal | Hex |
|---|---|---|---|
| 10 | 1010 | 12 | A |
| 15 | 1111 | 17 | F |
| 100 | 1100100 | 144 | 64 |
| 255 | 11111111 | 377 | FF |
Octal groups binary digits in threes, hex in fours: 1011 0110 = B6 hex; 10 110 110 = 266 octal.
Conversions
- Decimal to binary: divide by 2 repeatedly and read the remainders from the bottom up. 45: 45 → 22 r1 → 11 r0 → 5 r1 → 2 r1 → 1 r0 → 0 r1, so 101101.
- Binary to decimal: add the place values. 101101 = 32 + 8 + 4 + 1 = 45.
- Fractions: multiply by 2 and take the integer parts: 0.625 → 1.25 (1) → 0.5 (0) → 1.0 (1), so 0.101.
Signed integers
For n bits:
| Method | −5 in 8 bits | Range |
|---|---|---|
| Sign and magnitude | 1000 0101 | −127 to +127 (two zeros) |
| One's complement | 1111 1010 | −127 to +127 (two zeros) |
| Two's complement | 1111 1011 | −128 to +127 (one zero) |
Two's complement: invert every bit and add 1. Almost every computer uses it because addition and subtraction use the same circuit.
Two's complement arithmetic
To subtract, add the two's complement. Example in 8 bits: 20 − 5 = 20 + (−5):
0001 0100 + 1111 1011 = 1 0000 1111; drop the carry out: 0000 1111 = 15.
Overflow
The result does not fit in n bits. In two's complement it happens when two numbers of the same sign give a result of the other sign. Example: 100 + 50 in 8 bits: 0110 0100 + 0011 0010 = 1001 0110, which reads as −106: overflow (150 > 127). The carry out of the top bit alone does not signal signed overflow; the overflow flag compares the carries into and out of the top bit.
Binary-coded decimal
BCD stores each decimal digit in 4 bits: 59 = 0101 1001. Used where exact decimal digits matter (some calculators, clocks); wastes some codes (1010 to 1111 are unused).
Exams usually ask
- Convert between decimal, binary, octal and hex, including fractions.
- Represent negative numbers in the three signed forms.
- Perform two's complement addition and detect overflow.
Common mistake
Reading 1111 1011 as 251 when it is a signed byte. The same bits mean 251 unsigned and −5 in two's complement; the instruction decides which.
Written by the UniHive team in our own words. Spotted a mistake? Tell us on WhatsApp.
No reading links here yet
Our team adds free books, videos and practice for each topic, and opens every link before it goes up.