Number Representations and Computer Arithmetic

This is a Computer Science section: Digital Logic is Section 2 of the CS paper. The electronics and electrical papers have digital sections of their own with their own sub-lists, so if you are sitting one of those, read your own syllabus before assuming these three chapters are yours. What the section asks first is number representation, and the useful way in is to notice that a bit pattern means nothing on its own. 10110101 is 181, or −75, or a character, or a floating-point exponent field — the pattern does not say which; the interpretation does. Almost every question here is really asking which interpretation is in force. Three facts carry most of the marks. Two's complement is asymmetric: n bits hold −2n−1 to 2n−1−1, so an 8-bit byte reaches −128 but only +127, and that missing +128 is where questions about the negation of the most negative number come from. A carry is not an overflow: unsigned arithmetic overflows when a carry leaves the top bit, signed arithmetic overflows when the carry into the top bit differs from the carry out of it, and the two conditions are independent. And most decimal fractions have no exact binary form — 0.1 is a repeating binary fraction exactly as 1/3 is a repeating decimal — which is why floating-point comparisons fail and why the question is usually about precision rather than about magnitude.

Bases, and Reading a Pattern Two Ways

A positional base-r number is a sum of digits times powers of r, and conversion between binary, octal and hexadecimal needs no arithmetic at all: octal digits are three bits, hex digits are four, so 10110101 groups as 1011 0101 = B5 in hex and as 10 110 101 = 265 in octal. Converting to and from decimal is the only direction that costs work — repeated division by the base for the integer part, repeated multiplication for the fraction.

The same eight bits under four interpretations
Interpretation10110101 meansHow it is read
Unsigned181128 + 32 + 16 + 4 + 1
Two's complement−75Top bit set, so negate: invert to 01001010, add 1 → 01001011 = 75
Sign-and-magnitude−53Sign bit 1, magnitude 0110101 = 53
1's complement−74Invert to 01001010 = 74, negative
🎯 Why two's complement won, and what it costs
The other three representations each have two encodings of zero — sign-and-magnitude has +0 and −0, so does one's complement — and a comparator or an adder then needs a special case for it. Two's complement has exactly one zero, and subtraction becomes addition of the complement, so one adder does both operations with no extra hardware. That is the whole reason it is universal. The price is the asymmetry: with one zero and 2^n patterns, the negatives get one more slot than the positives, so 8 bits run −128 to +127. Negating −128 in 8 bits gives −128 back, because +128 has no representation — a fact worth knowing as a fact, since the arithmetic gives no warning.

Carry Is Not Overflow

Add 100 and 50 as 8-bit values: 01100100 + 00110010 = 10010110. No carry leaves the top bit, so unsigned arithmetic is content — 150 fits in a byte. Read the same result as signed and it is −106, which is wrong: two positive numbers cannot sum to a negative. So the signed operation overflowed while the unsigned one did not, from one addition, and any rule that treats the carry-out as "the" overflow flag gets this backwards.

Two independent conditions, two independent flags
FlagSet whenMatters to
CarryA carry leaves the most significant bitUnsigned results only
OverflowCarry into the MSB differs from carry out of itSigned results only
🧠 The sign test is faster than the carry test
You rarely need to trace carries. Signed overflow can only happen when the two operands share a sign, and it has happened exactly when the result carries the opposite sign. Positive + positive giving negative, or negative + negative giving positive, is overflow; operands of unlike sign can never overflow at all, because the magnitude of the sum is bounded by the larger of the two. That is one glance at three sign bits, and it is the check to use under time pressure.

Fixed and Floating Point, and IEEE 754

A fixed-point number puts the binary point at an agreed position, so the spacing between representable values is constant and the range is narrow. A floating-point number stores a sign, an exponent and a significand, so the spacing grows with magnitude — the trade the whole format exists to make. IEEE 754 single precision spends its 32 bits as 1 sign, 8 exponent, 23 significand, with the exponent stored biased by 127 and the leading 1 of a normalised significand implied rather than stored, which buys a 24th bit of precision for free.

Encoding −6.75 in IEEE 754 single precision, step by step
StepResult
SignNegative → 1
Magnitude in binary6.75 = 110.11
Normalise1.1011 × 2²
Exponent field2 + 127 = 129 = 10000001
Significand (leading 1 dropped)1011 then nineteen zeros
Full pattern1 10000001 10110000000000000000000
⚠️ 0.1 is not 0.1, and the question usually knows it
A decimal fraction is exactly representable in binary only when its denominator is a power of two. 0.5, 0.25 and 6.75 are exact; 0.1 and 0.3 are not, and store as the nearest 24-significant-bit value instead — which is why summing 0.1 ten times does not give 1, and why an equality test between floats is a bug rather than a comparison. The examinable consequences are worth separating from the folklore: the spacing between consecutive floats grows with the exponent, so adding a small number to a large one can change nothing at all; and floating-point addition is not associative, so (a + b) + c and a + (b + c) may genuinely differ. Range and precision are also separate questions — single precision reaches about 3.4 × 10³⁸ while holding only about seven decimal digits of precision, and a question asking "can this value be stored" is usually asking about the second.

Key takeaways

  • A bit pattern has no meaning without an interpretation — 10110101 is 181 unsigned and −75 in two’s complement.
  • n bits of two’s complement run −2n−1 to 2n−1−1: one zero, one extra negative, and no +2n−1.
  • Negate by inverting and adding one; negating the most negative number returns itself.
  • Carry belongs to unsigned arithmetic, overflow to signed — one addition can raise either, both or neither.
  • Signed overflow needs operands of the same sign and a result of the opposite one — check three sign bits, not the carries.
  • IEEE 754 single: 1 + 8 + 23 bits, exponent biased by 127, leading significand 1 implied not stored.
  • A decimal fraction is exact in binary only if its denominator is a power of two — 0.1 never is.
  • Float spacing grows with magnitude, so floating-point addition is not associative.

Practice questions (8)

Attempt each one before opening the answer. Every explanation names the tempting wrong option as well as the right one, because that is where marks are lost.

  1. The 8-bit pattern 10110101, interpreted as a two’s complement integer, is:

    1. 181
    2. −75
    3. −53
    4. −74
    Show answer

    Answer: B — −75

    The top bit is 1, so the value is negative and its magnitude is the two’s complement of the pattern: invert 10110101 to 01001010 and add one to get 01001011 = 75, so the value is −75. Every other option is the same pattern read under a different convention, which is the point of the question — 181 is the unsigned reading, −53 is sign-and-magnitude (sign bit plus 0110101 = 53), and −74 is one’s complement (invert only). A pattern does not carry its own interpretation, and a question that does not state one is usually testing exactly that.
  2. Two 8-bit values 01100100 and 00110010 are added. Which flags does the result raise?

    1. Carry only
    2. Signed overflow only
    3. Both carry and signed overflow
    4. Neither
    Show answer

    Answer: B — Signed overflow only

    The values are 100 and 50, summing to 150 = 10010110. No carry leaves the most significant bit, so the carry flag is clear and the unsigned result 150 is perfectly correct in a byte. But read as signed, two positive operands have produced a negative result (10010110 = −106), so signed overflow is set. That is the whole lesson: the two flags answer different questions and one addition can raise either without the other. Option C is what a candidate picks after learning "overflow means the result did not fit" without asking did not fit which interpretation.
  3. In 8-bit two’s complement, negating −128 gives:

    1. +128
    2. +127
    3. −128
    4. 0
    Show answer

    Answer: C — −128

    −128 is 10000000. Inverting gives 01111111 and adding one gives 10000000 again, so the negation returns −128. The reason is the asymmetry of the representation rather than an arithmetic slip: 8 bits hold −128 to +127, so +128 has no encoding at all and the operation has nowhere correct to land. The hardware raises the overflow flag; the value it produces is the input. Option A is the mathematically right answer and the representationally impossible one, which is exactly why it is the distractor.
  4. A signed integer is stored in 12 bits of two’s complement. What is the largest positive value it can hold?

    Numerical answer — type the value.

    Show answer

    Answer: 2047

    With n bits the range is −2n−1 to 2n−1−1, so 12 bits reach 2¹¹ − 1 = 2047 on the positive side and −2048 on the negative. The commonest wrong answer is 2048, from remembering the power and forgetting the −1 that the single zero encoding forces. Reading the range off the exponent n − 1 rather than n is the other half of the same habit: it is 2¹¹, not 2¹², because one of the twelve bits is spent on the sign.
  5. In IEEE 754 single precision, the exponent field of −6.75 is:

    1. 10000001
    2. 00000010
    3. 10000010
    4. 01111111
    Show answer

    Answer: A — 10000001

    6.75 is 110.11 in binary, which normalises to 1.1011 × 2², so the true exponent is 2. The field stores it biased by 127, giving 2 + 127 = 129 = 10000001. Option B is the unbiased exponent written straight into the field, which is the single commonest error in this topic; option D is the bias itself, which is the field for an exponent of zero (values between 1 and 2). The sign bit is 1 and the significand is 1011 followed by nineteen zeros, the leading 1 being implied rather than stored.
  6. Which of the following are true of IEEE 754 single-precision floating point? (More than one may be correct.)

    1. Addition is not associative
    2. 0.1 has an exact representation
    3. The gap between consecutive representable values grows with magnitude
    4. The leading bit of a normalised significand is stored explicitly
    Show answer

    Answer: A — Addition is not associative; C — The gap between consecutive representable values grows with magnitude

    A and C are true, and they are the same fact twice. Because the exponent scales the spacing, consecutive floats are far apart at large magnitudes and close together at small ones (C) — and that is precisely why adding a small number to a large one can round away entirely, making (a + b) + c differ from a + (b + c) (A). B is false: 0.1 is a repeating binary fraction, since its denominator is not a power of two, and is stored as the nearest 24-bit significand. D is false and is the format’s cleverest economy — a normalised significand always starts with 1, so that bit is implied, buying a 24th bit of precision from 23 bits of storage.
  7. The binary number 10110101 written in hexadecimal and octal respectively is:

    1. B5 and 265
    2. A5 and 245
    3. B5 and 245
    4. 5B and 265
    Show answer

    Answer: A — B5 and 265

    Group from the right, four bits for hex: 1011 0101 = B 5, so B5. Three bits for octal, padding the left group: 010 110 101 = 2 6 5, so 265. No arithmetic is needed in either direction, which is the practical point — hex and octal exist as compact spellings of binary, not as separate number systems to convert through decimal. Option D reverses the hex digits, which is what grouping from the left produces when the bit count is not a multiple of four; the padding always goes on the left.
  8. The decimal number 45 is stored in packed BCD. Reading those same eight bits as a plain unsigned binary number gives:

    1. 45
    2. 69
    3. 63
    4. 54
    Show answer

    Answer: B — 69

    Packed BCD stores each decimal digit in its own four bits, so 45 becomes 0100 0101. Read as one binary number that pattern is 64 + 4 + 1 = 69. Straight binary would have stored 45 as 00101101, a different pattern entirely. This is the interpretation problem of this chapter in its most practical form: BCD wastes range — four bits hold sixteen values and BCD uses ten — and buys something specific in return, which is that decimal digits convert to and from display without division. Option A is what a candidate answers by assuming a stored number reads back the same whatever convention is applied to it, which is the one assumption this whole section exists to break.