Two's Complement Calculator
Calculate two's complement binary, hexadecimal, octal, signed decimal, unsigned decimal, ranges, and sign information from a decimal integer and bit width. Two's Complement Calculator helps students, programmers, and engineers verify fixed-width binary representations accurately.
Highlights
- Convert signed decimal integers into fixed-width two’s complement binary.
- View equivalent hexadecimal, octal, signed decimal, and unsigned decimal values.
- Choose from 4-, 8-, 16-, or 32-bit representations.
- Check the minimum and maximum signed values for each bit width.
- Identify the sign bit and verify binary representations accurately.
Table of Contents
How Two's Complement Calculator Works?
The calculator represents a signed decimal integer as a fixed-width two's complement bit pattern. Select a width of 4, 8, 16, or 32 bits. The selected width determines the available signed range and the number of binary digits shown.
Here, n is the selected bit width. For example, an 8-bit signed value ranges from −128 through 127. Nonnegative values are written in ordinary binary and padded on the left with zeros. For a negative value x, the calculator obtains the fixed-width pattern by adding the modulus:
Equivalently, the bit pattern is the remainder of x modulo . For −42 in 8 bits, the encoded value is 256 − 42 = 214, which is binary 11010110. Its hexadecimal form is D6 and its octal form is 326. Because the most significant bit is 1, the signed interpretation is negative; interpreting the same bits as unsigned gives 214.
| Bit width | Minimum signed value | Maximum signed value | Unsigned pattern range |
|---|---|---|---|
| 4-bit | −8 | 7 | 0 to 15 |
| 8-bit | −128 | 127 | 0 to 255 |
| 16-bit | −32,768 | 32,767 | 0 to 65,535 |
| 32-bit | −2,147,483,648 | 2,147,483,647 | 0 to 4,294,967,295 |
The calculator then groups the same bit pattern into hexadecimal and octal digits, reports both signed and unsigned decimal interpretations, displays the minimum and maximum signed values for the selected width, and identifies the sign bit. The sign bit is the leftmost bit: 0 indicates a nonnegative signed value and 1 indicates a negative signed value.
Practical Use Cases
Students can use the calculator to check homework involving binary subtraction, sign bits, fixed-width ranges, and the process of representing a negative decimal value in two's complement.
Software developers can verify how a signed integer is stored or displayed at a specific width, especially when debugging bitwise operations, masks, shifts, casts, and hexadecimal values.
Embedded-systems programmers can confirm the representation of signed sensor readings, register fields, and control values in 4-bit, 8-bit, 16-bit, or 32-bit data structures.
Digital electronics students and engineers can compare a bit pattern's signed and unsigned interpretations while designing or testing arithmetic logic and binary data paths.
Systems and network engineers can inspect fixed-width fields in protocols, memory dumps, and debugging output by comparing binary, hexadecimal, octal, signed decimal, and unsigned decimal results.
Accuracy and Limitations
The calculator uses exact integer arithmetic for the supported 4-bit, 8-bit, 16-bit, and 32-bit widths, so the displayed binary, hexadecimal, octal, signed decimal, unsigned decimal, range, and sign-bit results are exact when the input is representable in the selected width. The decimal input accepts integers from −2,147,483,648 through 2,147,483,647, but a value must also fit the selected signed range; for example, 200 cannot be represented as an 8-bit signed value even though it is within the input field's overall limit. The calculator does not represent fractions, values wider than 32 bits, or alternative signed encodings such as sign-magnitude or one's complement.
Quick Examples
Example #1: Negative Integer in 8-Bit Format
Convert a negative decimal integer into its 8-bit two's complement representations.
Example #2: Positive Integer in 16-Bit Format
Represent a positive decimal integer using a 16-bit two's complement format.
Example #3: Minimum Value in 4-Bit Format
Examine the smallest signed integer representable in a 4-bit two's complement system.