Week 1 Exercises — Bits, Bytes & Binary; Intro to Logic Gates

exercises
computer-systems
binary
digital-logic

Practice exercises for week 1, covering 2026-07-27-course-intro-bits-bytes-binary and 2026-07-30-intro-to-logic-gates. Many are taken from or based on Tanenbaum, Structured Computer Organisation, 5th edition, Appendix A and Appendix B. See binary-number-representations and logic-gates for the reference material needed to solve these.

On the HTML site, fill in each blank with your answer (as a quoted string, e.g. "1010"), then click Run Code to check it. In the PDF, the Working callout is shown as a static answer key instead (interactive checking needs a browser).

Q1 — Decimal to binary conversion

Convert the following decimal numbers to binary (unsigned representation): 1984, 4000, 8192.

1984 →

4000 →

8192 →

Repeatedly divide by 2, reading the remainders bottom-to-top (or subtract the largest power of 2 not exceeding the remaining value) — see binary-number-representations#converting-decimal-to-binary.

  • \(1984 = 1024+512+256+128+64 = 2^{10}+2^9+2^8+2^7+2^6 \Rightarrow\) 11111000000
  • \(4000 = 2048+1024+512+256+128+32 = 2^{11}+2^{10}+2^9+2^8+2^7+2^5 \Rightarrow\) 111110100000
  • \(8192 = 2^{13} \Rightarrow\) 10000000000000 (a 1 followed by 13 zeros)

Q2 — Binary to decimal, octal, hexadecimal

What is \(1001101001\) (binary, unsigned) in decimal? In octal? In hexadecimal?

Decimal →

Octal →

Hexadecimal →

Sum the powers of 2 where a bit is set: \(1001101001_2 = 2^9+2^6+2^5+2^3+2^0 = 512+64+32+8+1 = 617_{10}\).

  • Octal: \(617 \div 8 = 77\) r\(1\); \(77 \div 8 = 9\) r\(5\); \(9 \div 8 = 1\) r\(1\); \(1 \div 8 = 0\) r\(1\)1151 (check: \(1\cdot512+1\cdot64+5\cdot8+1\cdot1=617\)).
  • Hex: \(617 \div 16 = 38\) r\(9\); \(38 \div 16 = 2\) r\(6\); \(2 \div 16 = 0\) r\(2\)269 (check: \(2\cdot256+6\cdot16+9=617\)).

Q3 — Counting \(k\)-digit radix-\(r\) numbers

How many different positive integers can be expressed in \(k\) digits using radix \(r\) numbers?

With \(k\) digits in radix \(r\), every combination from all-zeros to all-\((r-1)\)s is representable, giving \(r^k\) distinct values total (including 0). Excluding 0 leaves \(r^k - 1\) positive integers.

Q4 — Radix-32 (Manchester Mark 1)

One of the earliest computers (the Manchester Mark 1, 1949) was programmed with a radix-32 number system, with digits \(0, 1, \dots 9, A, B, \dots U, V\) (10 numerals + 22 letters = 32 symbols).

  1. Describe how a binary number can be converted into a radix-32 number.
  2. Describe how a decimal number can be converted into a radix-32 number.
  3. Convert the decimal numbers 1300 and 2300 to radix-32 representations.

1300 →

2300 →

  • (a) Binary → radix-32: since \(32=2^5\), group the binary digits into 5-bit groups starting from the least significant bit (pad the leftmost group with leading zeros if needed), then convert each 5-bit group (a value 0–31) to the corresponding single radix-32 digit (0–9, then A=10 … V=31).
  • (b) Decimal → radix-32: repeatedly divide by 32, recording each remainder (converting remainders 10–31 to A–V); the radix-32 digits are the remainders read in reverse (last remainder computed = most significant digit) — the same repeated-division method used for decimal → binary/octal/hex.
  • (c):
    • \(1300 \div 32 = 40\) r\(20\); \(40 \div 32 = 1\) r\(8\); \(1 \div 32 = 0\) r\(1\) → digits \(1, 8, 20\)(=K) → 18K. Check: \(1\cdot1024+8\cdot32+20=1300\).
    • \(2300 \div 32 = 71\) r\(28\); \(71 \div 32 = 2\) r\(7\); \(2 \div 32 = 0\) r\(2\) → digits \(2,7,28\)(=S) → 27S. Check: \(2\cdot1024+7\cdot32+28=2300\).

Q5 — Largest unsigned integer

What’s the largest unsigned integer that can be represented in:

  1. 10 bits
  2. 9 decimal digits
  3. 8 hexadecimal digits

(a) 10 bits →

(b) 9 decimal digits →

(c) 8 hexadecimal digits →

The largest value in \(n\) digits of radix \(r\) is \(r^n - 1\) (all digits at their maximum):

    1. \(2^{10}-1 = 1023\)
    1. \(10^9-1 = 999{,}999{,}999\)
    1. \(16^8-1 = 4{,}294{,}967{,}295\) (note: 8 hex digits = 32 bits, so this equals \(2^{32}-1\))

Q6 — Finger counting

What’s the largest number that can be counted to on ten fingers, if each finger can be considered to have two positions? Compare your answer to that in 5(a).

Ten fingers, each with 2 possible positions, is exactly 10 bits of information: \(2^{10}-1 = 1023\) — identical to 5(a), since “10 things each with 2 states” is a 10-bit binary number.

Q7 — Signed number formats

For each of the following decimal numbers, write down the 8-bit binary representation using signed magnitude, one’s complement, two’s complement, and excess-128 formats:

  1. \(-1\)
  2. \(-16\)
  3. \(-99\)

Answer as four comma-separated 8-bit codes, in the order signed-magnitude,ones-complement,twos-complement,excess-128 (e.g. "10000000,11111111,00000000,10000000" for 0).

(a) −1 →

(b) −16 →

(c) −99 →

Formats (see binary-number-representations): signed magnitude = sign bit + 7-bit \(|n|\); one’s complement (negative) = invert every bit of \(|n|\)’s 8-bit form; two’s complement (negative) = \(128+n\) as a 7-bit value, prefixed with a 1; excess-128 = \(n+128\) as a plain 8-bit unsigned value.

\(n\) Signed magnitude One’s complement Two’s complement Excess-128
−1 10000001 11111110 11111111 01111111
−16 10010000 11101111 11110000 01110000
−99 11100011 10011100 10011101 00011101

Q8 — Signed format ranges

What are the smallest and largest integers that can be represented in the following binary representations:

  1. 16-bit two’s complement
  2. \(n\)-bit one’s complement
  3. excess \(2^{m-1}\)
  • (a) 16-bit two’s complement: smallest \(=-2^{15}=-32768\), largest \(=2^{15}-1=32767\).
  • (b) \(n\)-bit one’s complement: symmetric about zero (it has two representations of 0), so smallest \(=-(2^{n-1}-1)\), largest \(=2^{n-1}-1\).
  • (c) excess \(2^{m-1}\) (\(m\)-bit field, bias \(2^{m-1}\)): stored value ranges \(0\) to \(2^m-1\), actual value = stored \(-\) bias. Smallest (stored \(=0\)): \(-2^{m-1}\). Largest (stored \(=2^m-1\)): \(2^{m-1}-1\) — the same numeric range as \(m\)-bit two’s complement, just a different (biased) encoding of it.

Q9 — Logic gates: NOR and XOR

Draw the logic symbol, write the Boolean function, and write down the truth table for:

  1. a 4-input NOR gate
  2. a 3-input XOR gate (i.e. the odd function)

(a) 4-input NOR — symbol: an OR-gate body (curved input side, pointed output) with 4 input lines and a small bubble on the output denoting inversion. Boolean function (De Morgan’s): \(X = \overline{A+B+C+D} = \bar A \cdot \bar B \cdot \bar C \cdot \bar D\)\(X=1\) only when every input is 0.

A B C D X
0 0 0 0 1
all other 15 combinations 0

(b) 3-input XOR (odd function) — symbol: an XOR-gate body (OR-gate shape with an extra curved line just behind the inputs), no bubble. Boolean function: \(X = A \oplus B \oplus C\)\(X=1\) iff an odd number of inputs are 1.

A B C X
0 0 0 0
0 0 1 1
0 1 0 1
0 1 1 0
1 0 0 1
1 0 1 0
1 1 0 0
1 1 1 1