All problems

Leftward loom shuttle offsets appear as large positive values

Level 1 · node · Data · Missing sign extension for twelve-bit two's complement values

Scenario

A fictional loom simulator stores each shuttle displacement relative to its reference position in the lower twelve bits of a sixteen-bit integer. The upper four bits represent status. Rightward displacements display correctly, but leftward displacements appear as large positive values. Review the displacement decoder and preview entry point.

Requirements

preview(words) accepts an array of integers from 0 to 65535 and returns a new array interpreting the lower twelve bits of each integer as a signed two's complement displacement. Displacements range from -2048 to 2047. Ignore the upper four bits, preserve input order and duplicates, and do not mutate the original array.

Acceptance criteria

  • Decode zero and positive displacements correctly.
  • Decode negative displacements and both representable limits correctly.
  • Return the same displacement regardless of the upper status bits.
  • Handle empty input and duplicates while preserving the input array.