Worked example
Operation: Decimal → bits a: -1 Bit width: 8
2⁸ + (−1) = 255 = 1111 1111₂
→ 1111 1111; hex: FF; 10: −1
Method and scope
Encode a signed decimal integer or decode an exact-width binary string (without spaces). The leading bit is the sign bit. Range: −2^(w−1) to 2^(w−1)−1. Out-of-range values are rejected, never silently wrapped.
negative x → 2ʷ + x