core practice · coding

Encode a binary compatibility fixture

Implement encodeRepresentations() without hard-coding the returned fixture. Return lowercase hexadecimal strings for four values: signed16Hex for -42 encoded as a 16-bit two's-complement integer, float32Hex for 0.15625 encoded as IEEE-754 binary32, utf8Hex for the string A€, and littleEndianHex for the 32-bit value 0x12345678 written little-endian.

The mechanism

Bits have no meaning until a representation gives them one. Width, signedness, byte order, numeric format, and text encoding are part of every data contract; the same bytes can describe different values when either side assumes a different representation.

Study Data Representation

Expected evidence

An object with signed16Hex, float32Hex, utf8Hex, and littleEndianHex derived from the requested representations.

Try this drill in the practice workspace →

Hints when you need them
  • Use fixed-width buffers or typed views so width and byte order are explicit.
  • A TextEncoder exposes UTF-8 bytes without assuming one byte per character.

Watch for these mistakes

  • Treating a hex dump as a value without stating width, signedness, and byte order
  • Comparing floating-point results as if every decimal fraction has an exact binary representation
  • Confusing Unicode code points with UTF-8 bytes or fixed-width characters

Check the sources

Browse all practice briefs