Sign, Ones', Twos' Complement & Offset Binary

Enter an integer and bit width to get sign-magnitude, ones' complement, twos' complement, offset binary and the unsigned reading at once. The reverse direction decodes a bit pattern back to a number.

Twos' complement range -128 ~ 127

Four representations

Unsigned1111 10110xFBunsigned reads = 251
Sign-magnitude1000 01010x85sign-magnitude reads = -5
Ones' complement1111 10100xFAones' complement reads = -5
Twos' complement1111 10110xFBtwos' complement reads = -5
Offset binary0111 10110x7Boffset binary reads = 123

Decode a bit pattern

The same pattern means different numbers under different encodings. Set the width and encoding.

= -5

Twos' complement is the one you meet most: 8-bit covers -128..127, 16-bit covers -32768..32767. Note that -128 has no sign-magnitude or ones' complement form at 8 bits, because the magnitude 128 does not fit — this page states that instead of printing a wrong value.

Offset binary is just the twos' complement value with the sign bit flipped; it shows up in float exponents and ADC offsets.

Comments

Sign in to join the discussion

No comments yet — be the first to say something