Number Representations and Computer Arithmetic
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.
| Flag | Set when | Matters to |
|---|---|---|
| Carry | A carry leaves the most significant bit | Unsigned results only |
| Overflow | Carry into the MSB differs from carry out of it | Signed results only |
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.
| Step | Result |
|---|---|
| Sign | Negative → 1 |
| Magnitude in binary | 6.75 = 110.11 |
| Normalise | 1.1011 × 2² |
| Exponent field | 2 + 127 = 129 = 10000001 |
| Significand (leading 1 dropped) | 1011 then nineteen zeros |
| Full pattern | 1 10000001 10110000000000000000000 |
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.
The 8-bit pattern 10110101, interpreted as a two’s complement integer, is:
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.Two 8-bit values 01100100 and 00110010 are added. Which flags does the result raise?
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.In 8-bit two’s complement, negating −128 gives:
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.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.In IEEE 754 single precision, the exponent field of −6.75 is:
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.Which of the following are true of IEEE 754 single-precision floating point? (More than one may be correct.)
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.The binary number 10110101 written in hexadecimal and octal respectively is:
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.The decimal number 45 is stored in packed BCD. Reading those same eight bits as a plain unsigned binary number gives:
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.