Two's Complement Calculator

Signed decimal to two's complement binary and hex.

Ad placeholder (leaderboard)
Enjoying the tools? Go Pro for £4.99 (one-time) and remove all ads — forever, on this device. Remove ads — £4.99

Two’s complement calculator

This tool shows how a signed decimal integer is stored in two’s complement form at 8, 16, 32, or 64 bits, with the binary pattern, the hexadecimal value, and both the unsigned and signed readings of the same bits. It is for programmers, students, and anyone debugging low-level numeric encodings.

How it works

Two’s complement is how nearly every modern CPU represents negative integers. For a width of w bits, a negative value −n is stored as 2^w − n, which makes the most significant bit act as a sign bit and lets addition and subtraction share one circuit. The tool masks your value to w bits and then:

binary   = the w-bit pattern of (value mod 2^w)
hex      = that pattern in base 16
unsigned = the pattern read as a non-negative number (0 … 2^w − 1)
signed   = the pattern read in two's complement (−2^(w−1) … 2^(w−1) − 1)

Each width has a fixed signed range; values outside it are flagged and shown wrapped. Big-integer arithmetic keeps even 64-bit results exact.

Example

For −42 at 8 bits: 2^8 − 42 = 256 − 42 = 214, whose 8-bit pattern is 11010110 (hex D6). Read as unsigned that is 214; read as signed two’s complement it is −42.

WidthSigned range
8-bit−128 … 127
16-bit−32,768 … 32,767
32-bit−2,147,483,648 … 2,147,483,647

Everything runs locally in your browser.

Ad placeholder (rectangle)