Skip to content
BCBinary Code Translator
Menu

Fixed-width signed integers

Two’s Complement Converter

Convert signed decimal, unsigned decimal, and exact binary bit patterns across 8, 16, 32, and 64-bit widths with strict range checks.

All arithmetic is performed locally with exact BigInt operations.

Bit pattern

No result yet

Hexadecimal pattern

No result yet

Signed decimal value

No result yet

Unsigned decimal value

No result yet

What two’s complement represents

Two’s complement is the standard way most computers store signed integers. A fixed-width register has a finite set of bit patterns. The lower half represent non-negative values, while patterns with the top bit set represent negative values. In eight bits, 01111111 is 127, 10000000 is -128, and 11111111 is -1. The same physical bits can also be read as unsigned values from 0 through 255, so width and interpretation are essential context.

This converter keeps those concepts separate. Signed decimal mode checks the legal signed range and produces the corresponding pattern. Unsigned decimal mode treats the input as the raw magnitude held by all bits. Bit-string mode requires exactly the selected number of bits and reports both interpretations. Nothing is rounded, truncated, or silently wrapped when a decimal input is outside the valid range.

How to use the two’s-complement converter

Choose the interpretation before entering a value; the same digits can mean different things under different modes.

  1. Select Signed decimal, Unsigned decimal, or Exact bit string according to the source you are analyzing.
  2. Choose 8, 16, 32, or 64 bits. This determines the legal ranges, padding length, sign bit, and hexadecimal width.
  3. Enter the value. Decimal modes accept a whole integer; bit mode accepts only 0 and 1 and requires exactly the selected width.
  4. Press Calculate to see the bit pattern, padded hexadecimal, signed decimal interpretation, and unsigned decimal interpretation.
  5. When copying a result into code or a debugger, preserve the width. Removing leading zeros can erase the information needed to identify the sign bit.

Two’s-complement examples

The examples below use eight bits unless another width is stated.

Input Bit pattern Explanation
42 signed, 8-bit 00101010 Positive values use their ordinary binary magnitude with leading zero padding.
-42 signed, 8-bit 11010110 Invert 00101010 and add one, producing the fixed-width representation of -42.
-1 signed, 8-bit 11111111 All ones represents -1 at every standard two’s-complement width.
128 unsigned, 8-bit 10000000 The raw pattern is valid unsigned 128 but represents signed -128.
32767 signed, 16-bit 0111111111111111 This is the largest signed 16-bit integer because the top bit remains zero.
-9223372036854775808 signed, 64-bit 8000000000000000 hex The minimum signed 64-bit value has only the sign bit set.

Widths, ranges, and accepted input

For a width of n bits, the signed range is -2ⁿ⁻¹ through 2ⁿ⁻¹-1. The unsigned range is 0 through 2ⁿ-1. Eight bits therefore allow signed -128 to 127 or unsigned 0 to 255. Sixty-four bits allow signed -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807, while the unsigned maximum is 18,446,744,073,709,551,615.

Decimal inputs may contain a sign plus spaces or underscores used as separators. Binary input may use a 0b prefix and visual spaces or underscores, but after formatting is removed it must contain exactly the selected width. Exact length prevents accidental sign extension or zero extension.

  • Signed decimal mode rejects values outside the signed range rather than wrapping them.
  • Unsigned decimal mode rejects negative numbers and values larger than the all-ones pattern.
  • Bit mode preserves leading zeros and always reports both signed and unsigned meanings.
  • Hex output is padded to 2, 4, 8, or 16 digits for 8, 16, 32, or 64 bits.

How two’s-complement conversion works

A non-negative signed value is stored as ordinary binary as long as it fits below the sign-bit boundary. A negative value x is mapped to 2ⁿ + x, where n is the width. For example, -42 in eight bits becomes 256 - 42 = 214, and 214 in binary is 11010110. This is equivalent to inverting the positive pattern and adding one.

To decode a bit pattern, the tool first reads it as an unsigned integer. If the top bit is zero, the signed value is the same. If the top bit is one, it subtracts 2ⁿ. Thus unsigned 214 becomes signed 214 - 256 = -42 in eight bits.

The arithmetic uses BigInt, including for 64-bit boundaries that cannot be represented exactly by JavaScript Number. Masks and padding are based on the selected width, so output remains deterministic across browsers.

Practical uses

Two’s complement appears anywhere fixed-width signed integers cross a boundary between raw bytes and human-readable values.

Debug registers and memory

Interpret a byte, word, or machine register shown by a debugger as both the signed value and its unsigned raw pattern.

Decode binary protocols

Verify signed sensor readings, counters, audio samples, and fields in network or device protocols with documented widths.

Write boundary tests

Generate exact patterns for minimum, maximum, -1, zero, and sign transitions in parsers, serializers, and database adapters.

Learn integer overflow

See why adding one to a maximum signed pattern changes the sign bit when hardware wraps within a fixed register.

Common mistakes and edge cases

Most errors come from omitting width or mixing signed and unsigned interpretations.

Using the wrong width

11111111 is -1 at eight bits, but if zero-extended to sixteen bits it becomes positive 255. Always keep the original field width.

Entering an out-of-range decimal

Signed 128 does not fit in eight bits, even though unsigned 128 does. Select the correct interpretation instead of expecting silent wrapping.

Dropping leading zeros

A shortened bit string may still have the same unsigned magnitude but no longer identifies the selected fixed-width representation.

Confusing sign-magnitude or one’s complement

Other historical signed encodings use different negative patterns. This tool implements only modern two’s complement.

Two’s complement is about interpretation within a width, not merely changing the printed base.

Decimal to binary

A basic converter may print -42 as -101010. Two’s complement instead produces the actual finite-width stored pattern such as 11010110.

Bitwise calculator

The bitwise calculator applies operations and masks. This page focuses on converting one value and exposing both signed and unsigned meanings.

IEEE-754 converter

IEEE-754 represents floating-point values with sign, exponent, and fraction fields. It is not two’s-complement integer storage.

Octal or hex converter

Base converters preserve mathematical value. Two’s-complement decoding can change the displayed signed value based on the top bit and width.

Frequently asked questions

Why is the signed range asymmetric?

One bit pattern is needed for zero, and two’s complement has only one zero. That leaves 2ⁿ⁻¹ negative values but 2ⁿ⁻¹-1 positive values, so eight bits range from -128 to 127.

Why does 11111111 equal both 255 and -1?

Bits do not carry a sign by themselves. Read as unsigned, all eight bits contribute to 255. Read as two’s-complement signed, the top bit indicates a negative value and the result is -1.

Can I enter fewer bits and have the tool pad them?

Bit-string mode is intentionally strict and requires the exact width. Automatic padding could choose zero extension when sign extension was intended, changing the meaning.

Does the converter simulate overflow?

Decimal conversion rejects out-of-range input. It does not silently wrap. The bitwise calculator is the better tool for explicitly width-limited operations.

Are 64-bit values exact?

Yes. BigInt is used for parsing, range checks, masks, and formatting, so all 64-bit signed and unsigned boundary values are exact.

Is hexadecimal output signed?

Hexadecimal output is the raw fixed-width bit pattern. Signedness applies when that pattern is interpreted as a decimal value, not to the hex digits themselves.

Related tools

View all tools

Cookie Preferences

Manage your cookie preferences. Necessary cookies cannot be disabled.

Necessary

Required

Required for language selection, privacy choices, and basic site functionality.

Cookies: NEXT_LOCALE

Analytics

Optional analytics cookies help us understand traffic and improve the website.

Cookies: _ga, _gid, _gat, _clck, _clsk

Advertising

Optional advertising cookies may be used to show relevant ads and measure performance.

Cookies: __gads, _gcl_au, IDE