Fixed-point converter
Encode a decimal value as a fixed-point word, or decode an existing bit pattern. All stored integers and conversions use exact integer arithmetic, including words wider than JavaScript’s native number precision.
Calculator
Representation and method
The represented value is the stored integer multiplied by 2−F. W includes every bit, including the sign bit for signed words. F may range from zero to W. Resolution is 2−F.
| Format | Minimum | Maximum |
|---|---|---|
| Signed | −2W−F−1 | 2W−F−1 − 2−F |
| Unsigned | 0 | 2W−F − 2−F |
For encoding, multiply the exact input decimal by 2F, apply the selected rounding rule, then apply the overflow policy. Saturation clamps to the signed or unsigned range. Wrapping keeps the least significant W bits. Decoding accepts an unsigned decimal integer, 0x hexadecimal, or 0b binary.
Worked example
With W = 16 and F = 12, −1.375 × 4096 = −5632. The two’s-complement word is 0xEA00. The resolution is exactly 0.000244140625.
Using the result in AMD Vitis HLS
For this convention, the corresponding integer width in ap_fixed<W,I> is I = W − F. Nearest with ties to even corresponds to convergent rounding. “Toward zero” and “toward −∞” are distinct for negative inputs. Explicitly select the HLS quantization and overflow modes to match this calculator. Scientific decimal input is accepted with an exponent within ±300.
Related tools
- FPGA memory sizing — Use the selected word width to estimate sample-storage requirements.
- DDS tuning-word calculator — Calculate the integer phase increment for a binary accumulator.
- VHDL entity and testbench generator — Declare signed or unsigned vectors for the chosen word format.
