Skip to question
asic.fyi
DesignVerificationSystemVerilogFirmwareArchitectureInterviews
asic.fyi/Interview questions/Decode IEEE-754 Binary32 and Binary64 Encodings

Hardware interview practice

Decode IEEE-754 Binary32 and Binary64 Encodings

MediumFirmwareC

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.

Try it in the question bankReason first. Then compare.

Keep this exact question selected while you check your answer and review the full solution.

Practice this question →
Starting point

Question code

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
Reviewed example

Work through one case

Input
Case 1: decode_fp32(0x3FC00000)
Case 2: decode_fp32(0x80000000)
Case 3: decode_fp64(0x7FF8000000000001)
Expected 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.

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.

What to cover

Requirements

  1. Extract sign, exponent field, and fraction field with unsigned masks/shifts; do not reinterpret by host floating-point arithmetic.
  2. 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.
  3. 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.
  4. 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.
asic.fyi · Learn silicon end to end.info@asic.fyi