GATE / CS ARCHIVE

SIMILAR QUESTIONS / COMPUTER ORGANIZATION & ARCHITECTURE

Encode numbers in a custom floating-point format

2 questions solved the same way, newest first. Back to Computer Organization & Architecture

How these are solved

Normalize the supplied numerical value, encode sign/fraction/exponent using the specified field widths and radix, and pack the fields.

Descriptive
Report issue

Encode a value in a custom hexadecimal float

Data Representation & Arithmetic

Question 9(a), GATE 2002: A 32-bit floating-point format has fields, from most to least significant: sign (1 bit), fraction (24 bits), exponent (7 bits). Sign 0 means positive and 1 negative. The binary point precedes the fraction bits. The exponent is stored in excess-64 representation, and the exponentiation base is 16. Represent decimal −7.5 as a normalized number in this format. Derive each field and give the complete representation in hexadecimal.
Question 9(a), GATE 2002: A 32-bit floating-point format has fields, from most to least significant: sign (1 bit), fraction (24 bits), exponent (7 bits). Sign 0 means positive and 1 negative. The binary point precedes the fraction bits. The exponent is stored in excess-64 representation, and the exponentiation base is 16. Represent decimal −7.5 as a normalized number in this format. Derive each field and give the complete representation in hexadecimal.
Tap to enlarge
Shared context

The custom 32-bit format stores sign, 24-bit fraction, then 7-bit excess-64 exponent, in that order. Its numeric value is (−1)^s(F/2^24)16^(E−64); no reserved exponent encodings are specified.

Answer & solution

Answer: Sign 1; fraction 0x780000; biased exponent 65; word 0xBC000041 (no official key was published)

1. Write the numeric interpretation of this particular format. For sign bit s, unsigned 24-bit fraction integer F, and unsigned stored exponent E, the value is (−1)s × (F/224) × 16E−64. The storage order is sign, fraction, exponent, unlike IEEE 754.

2. Normalize the magnitude in radix 16. Since 7.5/16 = 0.46875 and 0.46875 = 7/16 + 8/256, we have 7.5 = 0.78₁₆ × 16¹. The leading hexadecimal fraction digit 7 is nonzero, so this is normalized. Leading zeros within that hexadecimal digit’s four binary bits are allowed in radix-16 normalization.

3. Fill each field. The value is negative, so s=1. The six-hex-digit fraction is 780000, giving F=0x780000 and fraction bits 0111 1000 0000 0000 0000 0000. The actual exponent is 1; applying excess-64 gives E=65, whose seven-bit form is 1000001.

4. Concatenate the fields without moving the exponent to the front:

1 | 011110000000000000000000 | 1000001
= 1011 1100 0000 0000 0000 0000 0100 0001
= 0xBC000041

Equivalently, the word is (1 << 31) | (0x780000 << 7) | 65. The fraction is shifted by seven because the exponent occupies the low seven bits.

5. Decode the candidate to verify it: −(0x780000/224) × 1665−64 = −0.46875 × 16 = −7.5 exactly. No rounding is needed because the fraction has a finite binary and hexadecimal representation.

Original paper, page 7

2 marks · Descriptive
Report issue

Finite-mantissa encodings of two numbers

Data Representation & Arithmetic

Question 72(a), GATE 1997: A floating-point value is n=(f,e)=f·2^e. The fractional mantissa f has 6 bits including its sign bit, in sign-magnitude form. The exponent e has 4 bits including its sign bit, also sign-magnitude. A=54.75 and B=9.75 in decimal. No rounding mode, guard-bit convention, or normalization rule is explicitly supplied; use the conventional normalized fraction 1/2≤|f|<1 and state the rounding assumption. Represent A and B in this format.
Question 72(a), GATE 1997: A floating-point value is n=(f,e)=f·2^e. The fractional mantissa f has 6 bits including its sign bit, in sign-magnitude form. The exponent e has 4 bits including its sign bit, also sign-magnitude. A=54.75 and B=9.75 in decimal. No rounding mode, guard-bit convention, or normalization rule is explicitly supplied; use the conventional normalized fraction 1/2≤|f|<1 and state the rounding assumption. Represent A and B in this format.
Tap to enlarge
Answer & solution

Answer: With normalized mantissas and chopping: A→(0 11011,0 110)=54; B→(0 10011,0 100)=9.5. Neither original value is exactly representable. (no official key was published)

The six mantissa bits include the sign, leaving only five fraction-magnitude bits. The four exponent bits similarly leave three bits for its magnitude, so exponents range from −7 to +7, not the biased range of IEEE formats. Use a sign bit of 0 for each positive field.

Convert the values exactly first:
54.75=110110.11₂=.11011011₂×26,
9.75=1001.11₂=.100111₂×24.
Both normalized binary fractions need more than five magnitude bits. Therefore there is no exact six-bit-mantissa representation of either input under this normalization. A finite encoding requires a rounding rule; merely truncating without saying so would hide a loss of information.

Under chopping toward zero, retain the first five fraction bits:
A: mantissa 0|11011, exponent 0|110; value .11011₂×64=54.
B: mantissa 0|10011, exponent 0|100; value .10011₂×16=9.5.
The vertical bar separates the sign from magnitude. No hidden leading bit is added; all five fraction bits are explicitly stored. The exponent fields are the sign-magnitude representations of +6 and +4.

For comparison, round-to-nearest with ties-to-even gives A=54 again but B=10, encoded as mantissa 0|10100 with exponent 0|100. B=9.75 lies exactly halfway between 9.5 and 10; the retained significand integer for 10 is even. Other tie rules may choose differently. This alternative is not an official correction: it demonstrates why the source's missing rounding policy matters. The subsequent worked addition and 3.9% error use the explicitly stated chopping model throughout.

Original paper, page 10