Skip to content
UniKit

Signed number converter

Convert between binary, decimal and hex in sign-magnitude, one’s complement and two’s complement notation: widths 4 / 8 / 16 / 32 / 64, negative numbers, negative zero and overflow detection, plus grouped bits and the range of every representation.

Runs in your browserEvery computation happens in your browser — your data never leaves this device.

Notation
-5
Binary pattern1111 1011
Hex0xFB
Unsigned reading251

All representations

The same bit pattern means different things in different notations, so the table lists them separately; the unsigned row reads the current pattern as an unsigned number.

Sign-magnitude1000 01010x85= -5
One’s complement1111 10100xFA= -5
Two’s complement1111 10110xFB= -5
Unsigned1111 10110xFB= 251

Range for this width

Sign-magnitude-127 … 127
One’s complement-127 … 127
Two’s complement-128 … 127
Unsigned0 … 255

What this tool does

  • Convert -5 into its 8-bit two’s complement 11111011 while debugging embedded or low-level code, without doing the invert-and-add-one by hand.
  • Go the other way: take a bit pattern from a scope trace, a memory dump or a protocol spec and see what it means in two’s complement, one’s complement and sign-magnitude.
  • For homework or a lecture, lay out all four readings of the same bits in a table, complete with negative zero and the range of each notation.
  • Check overflow: 8-bit two’s complement only covers -128…127, so entering 200 is reported as out of range instead of being silently truncated.

Example

Input

Value mode, width 8 bits, notation two’s complement, input -5

Output

Bits 11111011 (grouped 1111 1011), hex FB, unsigned reading 251
Sign-magnitude 10000101 (85), one’s complement 11111010 (FA), two’s complement 11111011 (FB)

In decimal mode the bit pattern is built using the selected notation. The same bits mean different things in each notation, so the table lists them separately; the unsigned row simply reads the current pattern as an unsigned number.

Frequently asked questions

What is the actual difference between sign-magnitude, one’s complement and two’s complement?

Sign-magnitude uses the top bit as a sign and the rest as the absolute value (-5 → 10000101). One’s complement inverts every bit of the magnitude (-5 → 11111010). Two’s complement is one’s complement plus one (-5 → 11111011); it is what CPUs actually use because subtraction reuses the adder and there is no -0.

Why is the 8-bit range -127…127 for sign-magnitude and one’s complement but -128…127 for two’s complement?

Because 10000000 and 11111111 encode "negative zero" in the first two notations, wasting one code point, so the smallest value is -127. Two’s complement has no negative zero, so 10000000 is free to represent -128.

What happens if I type too few or too many bits?

Too few bits are left-padded with zeros — at 8 bits, 101 becomes 00000101. More bits than the width (nine binary digits at width 8) answers "Too many bits" and refuses to compute instead of silently truncating.

Do 64-bit values lose precision?

No. The whole conversion uses BigInt and never goes through Number, so a 64-bit two’s complement value such as -9223372036854775808 is exact. JavaScript bitwise operators (>>, &) would break above 32 bits — this tool does not use them.

Which hex formats are accepted?

An optional 0x prefix, either case, and spaces or underscores in between are all fine: FB, 0xff, FF and f f are equivalent. Binary accepts a 0b prefix and space grouping too (1111 1011).

Keywords:binarybitstwos complementones complementsign magnitude补码反码原码有符号位运算溢出

Related tools