Section 2 · 9 min read
Number representation and arithmetic
Base conversion, unsigned and signed integers (sign-magnitude, 1's and 2's complement), overflow, Booth multiplication, BCD, fixed point and IEEE 754 floating point, with GATE-style conversions worked step by step.
On this page
Why this topic scores
Questions here are mechanical, so they are free marks if you are careful: decode a 2's complement or IEEE 754 pattern, encode a decimal into IEEE 754 hex, decide whether an addition overflows, convert between bases, or reason about the range and precision of a made-up floating-point format. Most errors come from off-by-one mistakes in the exponent or from forgetting the hidden bit.
Positional number systems
In base , the digits mean . Digits must be less than , which is often the key constraint in "find the base" questions.
Conversions
- Base to decimal: expand the sum.
- Decimal integer to base : divide by repeatedly, collect remainders from last to first.
- Decimal fraction to base : multiply the fraction by repeatedly, collect the integer parts from first to last.
- Binary, octal, hexadecimal: group bits from the binary point outward, in threes for octal and fours for hex.
A decimal fraction has a finite binary expansion only if its denominator (in lowest terms) is a power of 2. So and are exact, but is forever.
Unsigned integers
bits represent to . Unsigned addition overflows when there is a carry out of the MSB. Unsigned subtraction done as produces carry out 1 when and 0 when a borrow occurs.
Signed integers
| Representation | Range for bits | Zeros | Negate |
|---|---|---|---|
| Sign-magnitude | to | two | flip the sign bit |
| 1's complement | to | two | invert all bits |
| 2's complement | to | one | invert all bits, add 1 |
| Excess- (biased) | to | one | stored value is |
2's complement in detail
The MSB has weight and every other bit has its usual positive weight:
That formula is the fastest way to decode. Example: .
- Sign extension: to widen a number, copy the sign bit into the new high positions. in 16 bits is FFDB.
- Negating the most negative number: has no positive counterpart, and negating it returns the same pattern.
- Shortcut for negation: copy bits from the right up to and including the first 1, then invert the rest.
Overflow
Adding two -bit 2's complement numbers overflows exactly when both operands have the same sign and the result has the other sign. Equivalent hardware test: overflow (carry out of the MSB XOR carry into the MSB). Adding numbers of opposite signs never overflows. A carry out of the MSB by itself means nothing for signed arithmetic.
In 1's complement addition, a carry out of the MSB is added back into the LSB (end-around carry).
Booth's multiplication (radix 2)
Booth's algorithm scans the multiplier from the right with an extra bit . For each pair :
| Pair | Action |
|---|---|
| 0 0 or 1 1 | shift only |
| 1 0 | subtract multiplicand (start of a run of 1s) |
| 0 1 | add multiplicand (end of a run of 1s) |
The number of additions and subtractions equals the number of bit changes in the multiplier with the appended 0. Booth is efficient for multipliers with long runs of 1s and worst for alternating patterns such as 0101...01 with , where every pair needs an operation.
BCD and other codes
BCD (8421) stores each decimal digit in 4 bits; codes 1010 to 1111 are unused. BCD addition: add the digits in binary; if the 4-bit result exceeds 9 or produces a carry, add 0110 and pass a carry to the next digit.
Excess-3 is BCD plus 3. It is self-complementing: inverting all bits gives the 9's complement of the digit.
Gray code: consecutive values differ in one bit. Binary to Gray is .
Fixed-point numbers
A fixed-point format puts the binary point at a fixed position. With integer bits and fraction bits in 2's complement, the stored integer is divided by . Range is to , and every step is exactly . Example: in 4.4 format, is the integer , so the value is .
IEEE 754 floating point
A floating-point number is for normalized values.
| Format | Sign | Exponent | Fraction | Bias |
|---|---|---|---|---|
| Single (32-bit) | 1 | 8 | 23 | 127 |
| Double (64-bit) | 1 | 11 | 52 | 1023 |
Special exponent fields
| Exponent field | Fraction | Meaning |
|---|---|---|
| all 0s | 0 | |
| all 0s | nonzero | subnormal: |
| 1 to max | any | normalized: |
| all 1s | 0 | |
| all 1s | nonzero | NaN |
Note the subnormal exponent is (that is for single), not . This makes the subnormals continue smoothly below the smallest normal number.
Key single-precision values
- Largest finite: .
- Smallest positive normalized: .
- Smallest positive subnormal: .
- Gap between 1 and the next representable number: .
- Integers are exact up to ; is the first that cannot be stored.
+0 and -0 have different bit patterns but compare equal. NaN compares unequal to everything, including itself.
Encoding a decimal number
- Write the magnitude in binary.
- Normalize to .
- Biased exponent , in binary.
- Fraction = the bits after the leading 1, padded with zeros (or rounded to nearest even if longer).
- Concatenate sign, exponent and fraction; group into hex.
Custom formats
GATE often defines a small format, for example 1 sign bit, exponent bits with bias , and fraction bits. Use the same rules: the largest exponent field is reserved, the largest finite value is , and the smallest normal is . Read the question carefully: some custom formats do not reserve the all-ones exponent, and some have no hidden bit.
Worked examples
Worked example 1: Base conversion
Convert to hexadecimal and to decimal.
Solution. , so the integer part is F3. , so the fraction is .4. Answer: .
.
Worked example 2: Overflow check
In 8-bit 2's complement, compute 5A + 4B (hex) and decide whether it overflows.
Solution. and , both positive. Binary sum: = A5. The result's MSB is 1, so it reads as . Two positives gave a negative: overflow. Carry into the MSB is 1 and carry out is 0, and agrees. The true sum 165 exceeds 127.
Worked example 3: Booth recoding
How many additions and subtractions does radix-2 Booth perform for the multiplier ?
Solution. Append 0: . Scanning pairs from the right, the only changes are at bit 2 (pair : subtract) and bit 6 (pair : add). So 2 operations. The recoding is , which matches . A plain shift-and-add multiplier would do 4 additions (one per 1 bit).
Worked example 4: Encode 12.375 in single precision
Solution. and , so .
- Sign: 0.
- Exponent: .
- Fraction: .
Bits: . Grouped in fours: = 41460000 (hex).
Worked example 5: Decode BE200000
Solution. Binary:
- Sign: 1.
- Exponent: , actual .
- Fraction: , significand .
Value: .
Worked example 6: A small format
A format has 1 sign bit, 5 exponent bits (bias 15) and 4 fraction bits, with IEEE rules. Find the largest finite value and the smallest positive subnormal.
Solution. Largest usable exponent field is , so the exponent is . Largest significand . Largest value .
Smallest subnormal: fraction , value .
Common traps
- Using the bias wrongly: actual exponent field bias, not field bias.
- Forgetting the hidden 1 for normalized numbers, or adding it for subnormals.
- Using instead of as the subnormal exponent in single precision.
- Grouping hex digits from the left when the bit count is not a multiple of 4. Pad on the left of the integer part (and the right of the fraction part).
- Treating carry out as signed overflow. Use the sign rule or .
- Writing the 2's complement range as symmetric. It is to .
- In BCD addition, forgetting to correct a digit that produced a carry even though its 4-bit result looks valid (for example needs the correction).
- Assuming 0.1 is stored exactly in binary floating point.
Quick revision
- 2's complement value: ; range .
- 1's complement and sign-magnitude: range , two zeros.
- Signed overflow: same-sign operands, different-sign result; .
- Sign extension: copy the sign bit.
- Booth: one operation per bit change in multiplier with appended 0.
- BCD add: if digit sum > 9 or carries, add 0110.
- IEEE single: 1/8/23, bias 127. Double: 1/11/52, bias 1023.
- Normal: . Subnormal: .
- Exponent all 1s: infinity (fraction 0) or NaN.
- Single: max , min normal , min subnormal .