Number representation and arithmetic
GATE CS70 min read
Positional number systems
Definition. In base , a digit string represents , where each digit satisfies . Binary, octal, decimal, and hexadecimal use bases 2, 8, 10, and 16. Hexadecimal digits A through F denote values 10 through 15.
Example. .
Exam point. A digit cannot be used if it is at least the base.
Base conversion by positional expansion
Definition. Convert a base- integer to decimal by summing digit-weight products; fractional digits have negative powers. For an integer in decimal, repeated division by the target base yields remainders read from last to first. For a fraction, repeated multiplication gives digits in order after the radix point.
Example. .
Exam point. Read integer remainders upward and fractional digits downward.
Solved calculation. Convert to binary.
- Integer part: gives remainders 1,0,1,1,0,1 when read upward, so .
- Fraction: , giving first bit 1 and remainder 0.25.
- , giving second bit 0 and remainder 0.5.
- , giving third bit 1 and remainder 0. Answer. .
Binary, octal, and hexadecimal conversion
Definition. Octal digits correspond to groups of three binary bits; hexadecimal digits correspond to groups of four. Group from the radix point outward, padding with zeros at the far left or right as needed. This conversion is exact because and .
Example. .
Exam point. Pad at the ends, not between bits or across the radix point.
Solved calculation. Convert to octal and hexadecimal.
- Octal grouping: , giving .
- Hex grouping: , giving .
- Check decimal: integer , fraction ; both forms agree. Answer. .
Unsigned fixed-width integers
Definition. An unsigned -bit word represents integers from 0 through . Leading zeros do not change its value. Addition that produces a carry beyond bit wraps modulo if the hardware discards that carry, while the carry flag may preserve information about unsigned overflow.
Example. In 4 bits, 1111 represents 15.
Exam point. Distinguish the stored low bits from the mathematical sum and carry-out.
Solved calculation. Add unsigned 4-bit values 1101 and 0111.
- Decimal values are 13 and 7; mathematical sum is 20.
- Binary addition is .
- The low four bits are 0100, and the carry-out is 1.
- As a 4-bit stored result the value is 4, with unsigned overflow indicated by carry. Answer. Stored result 0100, carry-out 1, mathematical sum 20.
Sign-magnitude representation
Definition. In an -bit sign-magnitude word, the most significant bit is the sign (0 positive, 1 negative) and the remaining bits give magnitude. The range is through and there are two encodings of zero. Arithmetic needs sign and magnitude handling rather than ordinary unsigned addition.
Example. In 8 bits, +5 is 00000101 and −5 is 10000101.
Exam point. Sign-magnitude has both +0 and −0.
One's-complement representation
Definition. In one's complement, a negative number is formed by complementing every bit of the positive magnitude representation. For bits, the range is through and zero has two encodings. Addition may require an end-around carry.
Example. In 8 bits, +5 is 00000101 and −5 is 11111010.
Exam point. Negative values are not formed by complementing only the magnitude field.
Two's-complement representation
Definition. In bits, two's-complement values range from through . A negative value is obtained by inverting all bits of the positive magnitude and adding 1, equivalently interpreting the top bit with weight . There is one zero encoding.
Example. In 8 bits, −5 is .
Exam point. The most negative value has no positive counterpart in the same width.
Solved calculation. Interpret 8-bit word 11101010 as signed two's complement.
- The sign bit is 1, so the value is negative.
- Invert bits: 00010101.
- Add 1: 00010110, which is 22.
- Therefore the original value is −22.
- Check the weighted sum: using bits 11101010: . Answer. −22.
Two's-complement range and overflow
Definition. An -bit two's-complement number has range . Signed overflow occurs when the exact mathematical result lies outside this interval. In addition, overflow occurs when equal-sign operands produce a result with the opposite sign; the carry into the sign bit differs from the carry out.
Example. In 4 bits, gives 1000, representing −8 although the sum is +8; overflow occurs.
Exam point. Carry-out alone does not determine signed overflow.
Solved calculation. Add 4-bit two's-complement values 0101 and 1100.
- Interpret operands: 0101 is +5; 1100 is −4.
- Add: .
- Keep four bits: 0001; carry-out is 1.
- Exact sum is +1, in range, and signs differ, so signed overflow is absent. Answer. Result 0001 (+1), no signed overflow.
Signed extension and truncation
Definition. To widen a two's-complement word, replicate its sign bit into new high positions; this preserves value. Zero extension is appropriate for unsigned values. Truncating high bits can change the value and is safe for signed arithmetic only when the removed bits are redundant sign copies and the retained sign remains consistent.
Example. Sign-extend 8-bit 11110110 (−10) to 12 bits: 111111110110.
Exam point. Never zero-extend a negative two's-complement value.
Solved calculation. Sign-extend 5-bit 10110 to 8 bits and interpret it.
- The original sign bit is 1; add three leading 1s: 11110110.
- In 5 bits, .
- In 8 bits, . Answer. 11110110, still −10.
Binary addition and subtraction
Definition. Binary addition uses the usual bit sums with carry. In fixed-width two's-complement arithmetic, subtraction is ; discard carry-out for the stored result, then check signed overflow separately. The same adder can perform both operations using conditional XOR inversion of .
Example. in four bits.
Exam point. Carry-out and signed overflow answer different questions.
Solved calculation. Compute 7−5 using four-bit two's complement.
- Encode +7 as 0111 and +5 as 0101.
- Complement 0101 to 1010 and add 1, obtaining 1011 (−5).
- Add .
- Keep four bits: 0010; exact result +2 is in range. Answer. 0010, which is +2.
Fixed-point representation
Definition. A fixed-point format assigns a fixed number of fractional positions. If a signed integer code is stored with fractional bits, its represented value is under the chosen signed encoding. The representable spacing is ; range depends on total width and sign convention.
Example. With four fractional bits, code integer 24 represents .
Exam point. The binary point is implied; it does not consume a storage bit.
Solved calculation. Interpret signed 8-bit two's-complement fixed point with 3 fractional bits, word 11110100.
- As an integer code, 11110100 represents −12.
- Divide by .
- The represented real number is . Answer. −1.5.
Fixed-point rounding and overflow
Definition. Quantization maps a real value to the nearest representable fixed-point value or follows a specified rounding rule. Truncation discards low fractional bits; round-to-nearest may reduce maximum error but needs a tie convention. Overflow occurs when the rounded value exceeds the format's finite range.
Example. With two fractional bits, 1.13 rounded to nearest quarter is 1.25.
Exam point. State whether truncation or rounding is used and how exact ties are handled.
Solved calculation. Quantize 2.6875 to a format with two fractional bits, using round-to-nearest, ties-to-even.
- The grid spacing is .
- Neighboring values are 2.50 and 2.75; distances are 0.1875 and 0.0625.
- Choose 2.75.
- Its scaled integer is 11, so the stored fractional code is . Answer. 2.75, encoded as 10.11 with two fractional bits.
Floating-point fields and value
Definition. A normalized binary floating-point number stores a sign bit, a biased exponent, and a fraction field. For a normal IEEE-style binary value, the significand is in base 2 and the value is . The hidden leading 1 is not stored in the fraction field.
You have read the free 29% of this note
Sign in with Google to keep reading. It is free, takes one tap, and you also get:
- 6 practice questions from this note
- Every note in full, plus the PDF library
- Official past papers as timed tests, with explanations
- An AI tutor for doubts, in Hindi or English
- Your progress, mistakes and study plan saved on every device