Source: Foundations of Computer Science, Ch. 3 (Sections 3.3 -- 3.5)
Tags: binary arithmetic, addition tables, multiplication tables, base conversion, division method, multiplication method, binary-to-hex, hex-to-binary, octal conversion, IFT 510, Purdue
Difficulty: Intermediate
Prerequisites: Number Systems, Bases, and Counting study notes (Ch. 3, Sections 3.0 -- 3.2)
Once you understand how numbers are represented in different bases, the next step is doing arithmetic with them and converting between them efficiently. Binary addition and multiplication are the foundation of how your computer's processor works at the hardware level. Conversion between binary, octal, and hexadecimal is something you will do constantly when reading memory dumps, debugging, or working with low-level data. This section gives you four conversion methods (two in each direction) and shows you how addition and multiplication tables work in non-decimal bases.
Arithmetic in other bases follows the same column-by-column rules you know from decimal; only the addition and multiplication tables change. To convert from another base to decimal, multiply each digit by its weight and sum. To convert from decimal to another base, repeatedly divide by the target base and read the remainders. Binary-to-hex and binary-to-octal conversions are a special shortcut: just group the bits.
Carry
The value that overflows from one digit position to the next during addition. In base 2, 1 + 1 = 10, so the result is 0 with a carry of 1. Think of it as the same "carrying" you learned in primary school, just with a different addition table.
Binary addition table
The complete table for adding any two single binary digits. Only four entries: 0+0=0, 0+1=1, 1+0=1, 1+1=10. In simple terms, the simplest possible addition table.
Binary multiplication table
Two-by-two table: 0x0=0, 0x1=0, 1x0=0, 1x1=1. Equivalent to the Boolean AND function.
Weights method (for base-to-decimal conversion)
Multiply each digit by its positional weight (base^position) and sum the results.
Successive division method (for decimal-to-base conversion)
Repeatedly divide the decimal number by the target base. The remainders, read from bottom to top, form the converted number.
Successive multiplication method (for base-to-decimal conversion)
Starting from the most significant digit, multiply the running total by the base and add the next digit. Repeat until all digits are processed.
Shift (left/right)
Moving all digits one position left multiplies the number by the base. Moving all digits one position right divides by the base. In binary, a left shift doubles the value; a right shift halves it. In simple terms, shifting is multiplication or division by the base, for free.
The only thing that changes when doing arithmetic in a non-decimal base is which addition or multiplication table you use. The carry rules, column alignment, and borrowing mechanics are identical to what you already know.
Base 2 addition table:
+ | 0 | 1 |
|---|---|---|
0 | 0 | 1 |
1 | 1 | 10 |
Base 2 multiplication table:
x | 0 | 1 |
|---|---|---|
0 | 0 | 0 |
1 | 0 | 1 |
The binary multiplication table is the Boolean AND function. The result bit in binary addition (ignoring the carry) is the EXCLUSIVE-OR function. The carry bit is the AND function. These logical equivalents are how computers implement arithmetic in hardware.
Add 11100001 and 101011:
1 1 1 0 0 0 0 1
+ 1 0 1 0 1 1
─────────────────────
1 0 0 0 0 1 1 0 0
Work right to left, carrying when the sum exceeds 1. Quick estimation check: 11100001 is roughly 128+64+32 = 224, and 101011 is roughly 32. The sum should be about 256. The result 100001100 = 256+8+4 = 268. Close enough to confirm correctness.
Binary multiplication is simpler than decimal multiplication. For each bit in the multiplier: if it is 0, write a row of zeros; if it is 1, copy the multiplicand shifted to the correct position. Then add all the rows.
Example: 1101101 x 100110
1101101 (multiplicand)
x 100110 (multiplier)
──────────
1101101 (shifted to the 2's place)
1101101 (shifted to the 4's place)
1101101 (shifted to the 32's place)
─────────────
1000000101110
Add 3FA, 5E1, and 6FC in hexadecimal:
3 F A
5 E 1
+ 6 F C
────────
1 0 D 7
Column by column from the right: A+1+C = 10+1+12 = 23 = 1x16 + 7, write 7, carry 1. F+E+F+1 = 15+14+15+1 = 45 = 2x16 + 13, write D, carry 2. 3+5+6+2 = 16 = 1x16 + 0, write 0, carry 1. Write the final carry: 1.
There are four methods to know. Two convert from base B to decimal, two convert from decimal to base B.
Write out the positional weights, multiply each digit by its weight, and sum.
Example, convert 13754 (base 8) to decimal:
Position: 8^4 8^3 8^2 8^1 8^0
Weight: 4096 512 64 8 1
Digit: 1 3 7 5 4
1x4096 + 3x512 + 7x64 + 5x8 + 4x1
= 4096 + 1536 + 448 + 40 + 4
= 6124
Start from the leftmost digit. Multiply by the base, add the next digit. Repeat.
Example, convert 13754 (base 8) to decimal:
Start with 1
1 x 8 = 8, 8 + 3 = 11
11 x 8 = 88, 88 + 7 = 95
95 x 8 = 760, 760 + 5 = 765
765 x 8 = 6120, 6120 + 4 = 6124
Same answer, often fewer mistakes with large numbers.
Find the largest power of the target base that fits into the number. Determine how many times it fits. Subtract and repeat for the next lower power.
Example, convert 6124 (decimal) to base 5:
Powers of 5: 15625, 3125, 625, 125, 25, 5, 1
15625 is too large. Start with 3125.
6124 / 3125 = 1 remainder 2999
2999 / 625 = 4 remainder 499
499 / 125 = 3 remainder 124
124 / 25 = 4 remainder 24
24 / 5 = 4 remainder 4
4 / 1 = 4
Result: 143444 (base 5)
Divide the number by the target base. Record the remainder. Divide the quotient again. Repeat until the quotient is zero. Read the remainders from last to first.
Example, convert 6124 (decimal) to base 5:
6124 / 5 = 1224 remainder 4 (least significant digit)
1224 / 5 = 244 remainder 4
244 / 5 = 48 remainder 4
48 / 5 = 9 remainder 3
9 / 5 = 1 remainder 4
1 / 5 = 0 remainder 1 (most significant digit)
Read top to bottom: 143444 (base 5) ✓
Example, convert 8151 (decimal) to hexadecimal:
8151 / 16 = 509 remainder 7
509 / 16 = 31 remainder 13 (D)
31 / 16 = 1 remainder 15 (F)
1 / 16 = 0 remainder 1
Result: 1FD7 (hex)
When one base is an exact power of another, conversion is a simple grouping exercise. Since 8 = 2^3, each octal digit maps to exactly 3 binary digits. Since 16 = 2^4, each hex digit maps to exactly 4 binary digits.
Binary to hexadecimal: Group bits by fours from the right. Pad with leading zeros if needed. Convert each group independently.
11010111011000 (binary)
Group: 0011 0101 1101 1000
Convert: 3 5 D 8
Result: 35D8 (hex)
Octal to binary: Replace each octal digit with its 3-bit binary equivalent.
275331 (octal)
2=010, 7=111, 5=101, 3=011, 3=011, 1=001
Result: 010111101011011001 (binary)
Hex to binary: Replace each hex digit with its 4-bit binary equivalent.
4F6A (hex)
4=0100, F=1111, 6=0110, A=1010
Result: 0100111101101010 (binary)
These conversions can be done mentally with practice. This is exactly why hex and octal are used as binary shorthand.
Positional value formula:
Value = sum of (digit_i x base^i) for all positions i
Range formula:
range = base^n (for n digits)
Left shift: multiply by base. Right shift: divide by base (integer division, fractional part lost).
When you look at a hex colour code #1FD7 in a web stylesheet, or a memory address like 0x0040A000, you are reading the output of exactly these conversion techniques. Debuggers display memory contents in hex because it is far more readable than binary and trivially convertible back. The division method is essentially what a printf("%x", number) call does internally when formatting a decimal integer as hex.
Students often read the remainders in the division method in the wrong order. The first remainder is the least significant digit (rightmost), not the most significant.
When grouping binary digits for hex conversion, students sometimes group from the left instead of the right. Always start grouping from the binary point (rightmost end for integers).
Forgetting to pad with leading zeros when grouping. If the leftmost group has fewer than 4 bits (for hex) or 3 bits (for octal), pad with zeros on the left.
Assuming you can convert directly between octal and hex. You cannot (8 and 16 are not powers of each other). Convert through binary instead.
⚠️ The successive division method is the most commonly tested conversion technique. Practise it until it is automatic.
⚠️ Binary-to-hex grouping (4 bits per hex digit) appears on nearly every exam involving this material.
⚠️ Know the binary addition table and be prepared to add multi-bit binary numbers with carries.
⚠️ The estimation technique (look at the most significant bit's weight, add half for the next bit) is recommended by the textbook for quick-checking exam answers.
⚠️ Shifting left by one bit doubles a binary number. Shifting right by one bit halves it (losing any fraction). This concept returns in later chapters on machine instructions.
1. True or false: In binary, 1 + 1 = 2. False. In binary, 1 + 1 = 10 (which represents two, but is written as "10" in base 2).
2. Fill in the blank: To convert decimal to hex using the division method, you divide repeatedly by ______. 16
3. True or false: The binary number 10110 in hex is B. False. 10110 in binary = 0001 0110 = 16 in hex. (That is, 1x16 + 6 = 22 decimal, or 16 hex.)
Actually let's recheck: 10110 = 16+4+2 = 22 decimal. 22/16 = 1 remainder 6, so hex 16. The answer is 16 (hex), not B.
4. Fill in the blank: Each octal digit corresponds to exactly ______ binary digits. 3
5. True or false: You can convert directly from octal to hexadecimal by simple digit grouping. False. 8 is not a power of 16 (nor vice versa). You must convert through binary first.
Q: Convert 3193 (decimal) to binary using the weights method.
A: Largest power of 2 that fits: 2048. 3193 minus 2048 = 1145. 1024 fits: 1145 minus 1024 = 121. 64 fits: 121 minus 64 = 57. 32 fits: 57 minus 32 = 25. 16 fits: 25 minus 16 = 9. 8 fits: 9 minus 8 = 1. 1 fits. Result: 110001111001 (binary).
Q: Convert 3193 (decimal) to hexadecimal using the division method.
A: 3193 / 16 = 199 remainder 9. 199 / 16 = 12 remainder 7. 12 / 16 = 0 remainder 12 (C). Reading top to bottom: C79 (hex).
Q: Convert the binary number 101101110111010 directly to hexadecimal.
A: Group from the right: 0101 1011 1011 1010. Convert each: 5 B B A. Result: 5BBA.
Q: Add the hexadecimal numbers 2AB3 and 35DC.
A: Column by column from right: 3+C = 15 = F. B+D = 22 = 1x16+6, write 6 carry 1. A+5+1 = 16 = 1x16+0, write 0 carry 1. 2+3+1 = 6. Result: 608F.
Q: Why is hexadecimal preferred over octal for representing binary in modern systems?
A: A 16-bit number maps exactly to 4 hex digits, and a 32-bit number maps exactly to 8 hex digits. Octal digits group 3 bits, which does not divide evenly into common word sizes (16, 32, 64 bits).
Binary arithmetic connects directly to how the ALU (arithmetic logic unit) works inside a processor (covered in later chapters on computer architecture). The conversion methods reappear when you study data formats (Chapter 4), where character codes and colour values are expressed in hex. Shifting operations are fundamental to multiplication and division instructions in assembly language. The relationship between binary and hex also matters for networking (IP addresses, MAC addresses) and security (hashing, encryption keys).
Related Terms / Search Tags: binary addition, binary multiplication, base conversion methods, division method, weights method, successive multiplication, binary to hexadecimal, hex to binary, octal to binary, carry bit, left shift, right shift, XOR addition, AND multiplication, IFT 510 Quiz 3, Purdue computer science