Skip to the selected question
ASIC.FYI

ASIC Question Bank

1,000+ hardware interview questions
DescriptionQ144
Page ↗
Q144FWAMDASIC interview problem

Decode IEEE-754 Binary32 and Binary64 Encodings

TechniquesFWDesignFirmware
DifficultyMedium
TopicFirmware
LanguageC
Requirements4 checkpoints
01

Problem

Firmware must classify raw IEEE-754 bit patterns without performing floating-point arithmetic. It returns sign, class, unbiased exponent for finite nonzero values, and the raw significand including the implicit leading bit for normal values. Implement binary32 and binary64 decoders with exact normal, subnormal, zero, infinity, and NaN rules.

Starting declarationC
fp32_dec_t decode_fp32(uint32_t bits);
fp64_dec_t decode_fp64(uint64_t bits);
// class: FP_ZERO, FP_SUBNORMAL, FP_NORMAL, FP_INF, FP_NAN
// fp32 fields 1/8/23, bias 127; fp64 fields 1/11/52, bias 1023
// normal significand prepends 1; subnormal prepends 0

Example input and output

Use this case to check your interpretation
Input
Case 1: decode_fp32(0x3FC00000)
Case 2: decode_fp32(0x80000000)
Case 3: decode_fp64(0x7FF8000000000001)
Output
Case 1: sign=0, class=FP_NORMAL, exponent=0, significand=0xC00000, representing 1.5.
Case 2: sign=1, class=FP_ZERO, exponent=0, significand=0.
Case 3: sign=0, class=FP_NAN, exponent=0, significand=0 under the stated special-output convention.
Explanation

The shown result follows by applying this rule: Field widths, biases, hidden-bit rules, and all five classes are correct for both formats. The cases also demonstrate this requirement: Return a 24-bit raw significand for binary32 and 53-bit raw significand for binary64; special classes set exponent/significand outputs to zero for this interface.

02

Requirements (4)

  • Extract sign, exponent field, and fraction field with unsigned masks/shifts; do not reinterpret by host floating-point arithmetic.
  • All-zero exponent with zero fraction is signed zero; all-zero exponent with nonzero fraction is subnormal with effective exponent `1-bias` and no hidden one.
  • All-one exponent with zero fraction is infinity; all-one exponent with nonzero fraction is NaN. Other patterns are normal with unbiased exponent `exp-bias` and an implicit leading one.
  • Return a 24-bit raw significand for binary32 and 53-bit raw significand for binary64; special classes set exponent/significand outputs to zero for this interface.