Sign-magnitude, ones’ and two’s complement
Sign-magnitude, ones’ complement and two’s complement of decimal integers, one per line, at 8, 16, 32 or 64 bits.
Process locally
Files stay in this browser session. Closing or clearing releases them.
Add text
Type or paste the text to process
Adjust settings
Optional: Bit width
Run
Processes in this browser; cancel at any time
About this tool
Work out the sign-magnitude, ones’ complement and two’s complement forms of decimal integers at 8, 16, 32 or 64 bits. It helps with computer architecture classes and homework, or when you want to see how a negative number is stored in memory. Put one number per line to get a whole list in one run.
Bits are grouped in fours, and the two’s complement is also shown in hex: at 8 bits, -5 is 1000 0101 in sign-magnitude, 1111 1010 in ones’ complement and 1111 1011 (FB) in two’s complement. Only decimal integers are accepted, and the work is done in your browser.
How to use it
- Under “Add text”, type one decimal integer per line, or select Use example.
- Choose the “Bit width”: “8-bit”, “16-bit”, “32-bit” or “64-bit”. The default is 8-bit.
- Select Run.
- Check each number’s sign-magnitude, ones’ complement, two’s complement and hex in the preview, then download the results as a text file.
Formats and limits
- Input
- Text
- Output
- Plain text
- Size limit
- 1 MB
- Settings
- Bit width (8-bit, 16-bit, 32-bit, 64-bit)
- Privacy
- Files stay in the current browser session. No file bytes are uploaded.
- Price
- Free, no sign-up
Common questions
Why do sign-magnitude and ones’ complement show n/a for -128?
At 8 bits, sign-magnitude and ones’ complement only cover -127 to 127, so -128 exists only in two’s complement, as 1000 0000. The same goes for the smallest negative number at every width.
Are the three forms different for positive numbers?
No. Positive numbers and zero look the same in all three. For a negative number, ones’ complement flips every bit of the sign-magnitude form except the sign bit, and two’s complement adds 1 to that.
What if a number is out of range?
Each width has a limited range: -128 to 127 at 8 bits, -32768 to 32767 at 16 bits and -2147483648 to 2147483647 at 32 bits. A number outside the range stops the run with an error, so pick a wider bit width.
Can I enter hex numbers or decimals?
No, only decimal integers, with an optional sign; spaces and underscores inside a number are ignored. To convert between hex, binary and other bases, use the “Number base converter” tool.
Is 64-bit exact?
Yes. The tool calculates with arbitrary-precision integers, so every value from -9223372036854775808 to 9223372036854775807 comes out exactly.
Related tools
Number base converter
Convert integers of any size between bases 2 and 36, one per line, with optional two’s complement for signed 8 to 128-bit values.
IEEE 754 float converter
Show the single or double-precision bits of decimal numbers, or read hex and binary bit patterns back as numbers, one per line.
Byte radix and endianness converter
Convert bytes between hex, binary, octal, unsigned or signed decimal, Base64 and UTF-8 text, and swap byte order between big and little endian in 2, 4 or 8-byte words.
Base16/32/58/64/85/91 encoding
Encode or decode Base16, Base32, Base58, Base62, Base64, Ascii85, Z85 and basE91, choosing the character set of the text, or hex for raw bytes.
Base64 to image or file
Turn Base64 or a data: URI back into a file such as an image; the type comes from the content or the URI.
Character set encoding and mojibake repair
Show the bytes of text in UTF-8, GBK, GB18030, Big5, Shift_JIS and more as hex, turn hex back into text, or repair mojibake from text read in the wrong character set.