Binary file formats
Fixed-point byte encoder
Quantize a decimal value to signed or unsigned fixed-point bytes.
Your inputs
Start with an exampleYour result
Example resultAa — A small example of your colors.
How it works
Multiply by 2^fractionalBits and round ties away from zero. Encode negative stored integers in two’s complement. Divide back to show the represented value.
−1.5 with 8 fractional bits stores −384. In signed 16-bit big-endian form, the bytes are FE 80.
Limits
Overflow is rejected instead of wrapped. Inputs use JavaScript numeric precision; supported storage widths are 8, 16, 24 and 32 bits.