Twos Complement Calculator
Convert any signed integer into its twos complement binary and hexadecimal form at the bit width you choose, or decode a bit pattern back into a signed value.
How to find twos complement
- Choose the bit width, such as 8, 16 or 32 bits.
- Enter the signed integer you want to represent.
- Read the twos complement binary, hex and unsigned value.
Examples
Encode -1 in 8 bits
Value -1, width 8 bits
Binary 11111111, hex 0xFF, unsigned 255
Frequently asked questions
What is twos complement?
Twos complement is the standard way computers store signed integers. A negative value is the bit pattern you get by adding 2 to the power of the bit width, so -1 in 8 bits is 11111111.
How do I calculate twos complement by hand?
Write the positive value in binary, flip every bit, then add 1. The result is the twos complement form, which this tool computes for you at any width.
Why is the range not symmetric?
An n-bit signed integer runs from minus 2 to the power n minus 1 up to 2 to the power n minus 1, minus 1. For 8 bits that is -128 to 127, so there is one more negative value than positive.
What does the unsigned value mean?
It is the same bit pattern read as a plain unsigned number. For -1 in 8 bits the pattern 11111111 equals 255 when treated as unsigned.
Can it decode binary back to a number?
Yes. Enter a bit pattern of the chosen width and the tool reads the top bit to decide the sign and returns the signed integer it represents.
Related tools
Number Base Converter
Convert numbers between any base from 2 to 36, including binary, octal, decimal and hex. Handles huge numbers exactly with arbitrary precision. Free, private.
UUID Generator
Generate random version 4 UUIDs online. Create one or thousands at once, with uppercase or no-hyphen options, then copy them. Free and private.
.env to JSON
Convert a .env file to JSON, or JSON back to .env. Parses KEY=value lines, comments, quotes and export. Runs entirely in your browser.
Aspect Ratio Calculator
Calculate aspect ratios fast. Enter a ratio like 16:9 and one dimension to get the other, or enter width and height to simplify the ratio.
Base32 Encode
Base32 encode and decode text online using the standard RFC 4648 alphabet with proper padding. UTF-8 safe, fast and private in your browser.
Base58 Encoder
Encode and decode Base58 online with the Bitcoin alphabet. Convert text to Base58 or back, UTF-8 safe, no confusing 0 O I l. Runs in your browser.