The Binary System — Exercises I: Step-by-Step SolutionsThe binary numeral system is the foundation of modern digital electronics and computing. Using only two symbols, 0 and 1, binary encodes values, represents instructions, and models logical states. This article walks through a set of exercises labeled “Exercises I” and provides clear, step-by-step solutions to help learners build confidence converting between binary and decimal, performing basic arithmetic in binary, and understanding common representations such as unsigned integers, signed integers (two’s complement), and simple fractional values.
Why learn binary?
Understanding binary strengthens your grasp of how computers store and process data. Tasks such as debugging low-level code, designing digital circuits, or studying networking protocols all require fluency with binary concepts. Exercises with worked solutions are one of the most effective ways to solidify these skills.
Exercise set and solutions
The exercises progress from straightforward conversions to arithmetic operations and interpretation of signed numbers. Each problem statement is followed by a stepwise solution and a short explanation of the result.
Exercise 1 — Convert binary to decimal
Problem: Convert 1101012 (binary) to decimal.
Solution:
- Write the binary digits with their place values (starting from 0 on the right): 1101012 = 1·2^5 + 1·2^4 + 0·2^3 + 1·2^2 + 0·2^1 + 1·2^0
- Compute powers of two: 2^5 = 32, 2^4 = 16, 2^3 = 8, 2^2 = 4, 2^1 = 2, 2^0 = 1
- Multiply and sum: 1·32 + 1·16 + 0·8 + 1·4 + 0·2 + 1·1 = 32 + 16 + 0 + 4 + 0 + 1 = 53
Answer: 53 (decimal)
Explanation: Each binary digit (bit) contributes its value multiplied by a power of two. Summing those contributions yields the decimal equivalent.
Exercise 2 — Convert decimal to binary
Problem: Convert 78 (decimal) to binary.
Solution:
- Repeatedly divide by 2 and record remainders (least significant bit first): 78 ÷ 2 = 39 remainder 0
39 ÷ 2 = 19 remainder 1
19 ÷ 2 = 9 remainder 1
9 ÷ 2 = 4 remainder 1
4 ÷ 2 = 2 remainder 0
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1 - Read remainders from last to first: 7810 = 10011102
Answer: 1001110 (binary)
Explanation: Division by two extracts each bit from least to most significant; reversing the remainder list produces the binary representation.
Exercise 3 — Binary addition
Problem: Add 1011012 + 111012.
Solution:
- Align the numbers by place value: 101101
- 11101
- Add bit by bit from right to left with carries:
- Rightmost column: 1 + 1 = 10 (binary) → 0, carry 1
- Next: 0 + 0 + carry 1 = 1 → write 1, carry 0
- Next: 1 + 1 = 10 → 0, carry 1
- Next: 1 + 1 + carry 1 = 11 → 1, carry 1
- Next: 0 + 1 + carry 1 = 10 → 0, carry 1
- Leftmost: 1 + carry 1 = 10 → write 0, carry 1 (then write carry)
- Result bits (left to right): 1100011
Answer: 11000112
Check in decimal:
- 1011012 = 4510
- 111012 = 3010
- Sum = 7510
- 11000112 = 7510 — matches.
Explanation: Binary addition follows the same carry concept as decimal; checking by converting to decimal verifies correctness.
Exercise 4 — Binary subtraction using two’s complement
Problem: Compute 1001002 − 110112 (both 6-bit values), treating numbers as signed two’s complement integers.
Solution: Step A — Interpret the two’s complement signed values:
- For 1001002 (6 bits), the most significant bit (MSB) is 1 → negative number. To find its value: compute two’s complement (invert bits, add 1). Invert 100100 → 011011. Add 1 → 011011 + 1 = 011100. 0111002 = 28 (decimal). So 1001002 represents −28.
- For 110112 (6 bits), MSB is 1 → negative. Invert 110111 → wait—correct process: invert 110112 = 001001, add 1 → 001001 + 1 = 001010. 0010102 = 10 (decimal). So 110112 represents −10.
Step B — Compute subtraction interpreted as signed: (−28) − (−10) = (−18).
Step C — Represent −18 in 6-bit two’s complement:
- +18 in binary (6 bits): 010010 (16 + 2).
- Take two’s complement to get negative: invert → 101101, add 1 → 101110.
Answer: 101110 (6-bit two’s complement) = −18 (decimal)
Check: Convert 101110 as two’s complement:
- MSB 1 → invert 101110 → 010001, add 1 → 010010 = 18 → negative → −18.
Explanation: Two’s complement makes subtraction uniform by converting the subtrahend to its additive inverse and adding.
Exercise 5 — Binary fractions (fixed-point)
Problem: Convert 101.1012 to decimal (binary point indicates fractional part).
Solution:
- Separate integer and fractional parts: integer = 1012, fraction = .1012.
- Integer part: 1012 = 1·2^2 + 0·2^1 + 1·2^0 = 4 + 0 + 1 = 5.
- Fractional part: .1012 = 1·2^−1 + 0·2^−2 + 1·2^−3 = ⁄2 + 0 + ⁄8 = 0.5 + 0.125 = 0.625.
- Sum: 5 + 0.625 = 5.625
Answer: 5.625 (decimal)
Explanation: Bits right of the binary point represent negative powers of two, analogous to decimal fractions.
Exercise 6 — Convert decimal fraction to binary (limited precision)
Problem: Convert 0.3 (decimal) to binary with 8 fractional bits (approximate).
Solution:
- Multiply fractional part by 2 repeatedly, recording integer part each step: 0.3 × 2 = 0.6 → bit 0
0.6 × 2 = 1.2 → bit 1 (subtract 1 → 0.2)
0.2 × 2 = 0.4 → bit 0
0.4 × 2 = 0.8 → bit 0
0.8 × 2 = 1.6 → bit 1 (subtract 1 → 0.6)
0.6 × 2 = 1.2 → bit 1 (subtract 1 → 0.2)
0.2 × 2 = 0.4 → bit 0
0.4 × 2 = 0.8 → bit 0 - Eight fractional bits collected: 0.01001100 (binary fractional).
- Combine with integer part 0: 0.010011002 ≈ decimal 0.296875.
Answer: ≈ 0.01001100 (binary) ≈ 0.296875 (decimal)
Explanation: Many decimal fractions (like 0.3) are repeating in binary; truncation to 8 bits gives an approximation.
Exercise 7 — Bitwise operations (AND, OR, XOR)
Problem: Compute bitwise AND, OR, XOR for 1101102 and 1010112.
Solution:
- Align: 110110 101011
- Compute per bit:
- AND: 100010 (1&1=1, 1&0=0, etc.)
- OR: 111111
- XOR: 011101
Answers:
- AND = 100010 (binary)
- OR = 111111 (binary)
- XOR = 011101 (binary)
Explanation: Bitwise ops are applied independently per bit across aligned operands.
Exercise 8 — Overflow in fixed-bit addition
Problem: Add two 4-bit unsigned numbers: 11012 + 10112. Identify overflow.
Solution:
- Convert to decimal or add in binary: 1101 (13) + 1011 (11) = 24 decimal.
- The maximum representable unsigned value in 4 bits is 15. 24 > 15, so overflow occurs.
- Binary addition yields: 1101
- 1011 —— (1)10000 — result needs 5 bits; lower 4 bits are 0000, carry out 1 indicates overflow.
Answer: Result binary = 10000 (requires 5 bits); overflow occurred.
Explanation: Unsigned arithmetic overflows if the sum exceeds the fixed-width capacity.
Exercise 9 — Convert 2’s complement negative to decimal
Problem: Interpret 11101012 as an 8-bit two’s complement integer.
Solution:
- MSB = 1 → negative number.
- Find magnitude: invert bits → 0001010, add 1 → 0001011 = 11 decimal.
- Value = −11.
Answer: −11 (decimal)
Exercise 10 — Combined challenge
Problem: Compute (decimal) 23 + (binary) 10110 + (binary fractional) 10.01 and give the result in binary.
Solution:
- Convert all to binary aligned to fractional bits; choose two fractional bits for 10.01.
- 23 decimal in binary = 10111.00 (adding .00 fractional)
- 10110 (binary) = 22 decimal = 10110.00 or 10110.00
- 10.01 (binary) = 2.25 decimal
- Add decimals to check: 23 + 22 + 2.25 = 47.25
- Represent 47.25 in binary:
- Integer 47 = 32 + 8 + 4 + 2 + 1 → 101111
- Fraction .25 = .01 → 101111.01
Answer: 101111.01 (binary) = 47.25 (decimal)
Tips for practicing binary
- Convert back and forth to decimal to check answers.
- For signed numbers, always note the bit width and MSB.
- Use two’s complement for subtraction and negative representations.
- For fractions, remember digits right of the point are negative powers of two.
- When doing fixed-width arithmetic, watch for overflow and underflow.
If you want, I can convert these exercises into printable worksheets, add more problems by difficulty level, or provide short practice quizzes with instant answers.
Leave a Reply