Free Tool Two’s Complement Signed Binary Bit Width

Binary Sign Extension Calculator

Extend a signed two’s-complement binary number to a larger bit width without changing its numeric value. Inspect the repeated sign bits, decimal interpretation, hexadecimal equivalent, original width, target width, and final extended binary pattern.

Two’s complement
Positive & negative
4–64 bit widths
Browser based
Quick sign-extension example
10010110
11111111 10010110
±
Signed Binary Width Extender
TWO’S COMPLEMENT
Extended binary result
1111111110010110
8-bit signed value extended to 16 bits
Sign bit 1
Decimal value -106
Source width 8 bits
Target width 16 bits
Hex FF96
Original 10010110
Sign extended 1111111110010110
11111111
10010110
Overview

What Is Binary Sign Extension?

Binary sign extension increases the bit width of a signed two’s-complement binary number while preserving its original numeric value.

When a signed binary number is moved from a smaller data type to a larger one, the new high-order bits cannot simply be filled with zeros in every case. The most significant bit of a two’s-complement value is the sign bit, so that bit must be copied into every new position added on the left.

If the original sign bit is 0, zeros are added. If the sign bit is 1, ones are added. This preserves the value when increasing from widths such as 8 bits to 16 bits, 16 bits to 32 bits, or 32 bits to 64 bits.

0 Positive sign bit is extended with zeros
1 Negative sign bit is extended with ones
Same value Numeric interpretation must not change
Left side New bits are added before the original pattern
How It Works

How to Sign Extend a Binary Number

01
Identify the source width Determine how many bits belong to the original signed representation.
02
Read the sign bit The leftmost bit is 0 for a nonnegative value and 1 for a negative two’s-complement value.
03
Calculate how many bits must be added Subtract the source width from the target width.
04
Repeat the sign bit Prepend that many copies of the sign bit to the original binary value.
Positive Example

Sign Extending a Positive Binary Number

Consider the signed 8-bit value 01100101. Its sign bit is 0, so it represents a nonnegative number.

8-bit → 16-bit positive sign extension +101
Original: 01100101 Sign bit: 0 Decimal value: 101 Bits to add: 16 – 8 = 8 Extension bits: 00000000 16-bit result: 0000000001100101 Decimal value after extension: 101

Because the sign bit is zero, the eight additional high-order bits are also zeros. The extended representation still represents decimal 101.

Negative Example

Sign Extending a Negative Two’s-Complement Number

Now consider 10010110 as an 8-bit signed integer. Because the first bit is 1, the value is negative.

8-bit → 16-bit negative sign extension -106
Original: 10010110 Sign bit: 1 Signed decimal: -106 Bits to add: 16 – 8 = 8 Extension bits: 11111111 16-bit result: 1111111110010110 Signed decimal after extension: -106 Hex: FF96

Filling the new positions with zeros would incorrectly change the sign and numeric value. Repeating the leading 1 preserves the original two’s-complement interpretation.

Reference

Common Sign Extension Examples

Original Source width Decimal Target width Extended result
01111111 8 127 16 0000000001111111
10000000 8 -128 16 1111111110000000
11111011 8 -5 16 1111111111111011
00000001 8 1 32 00000000000000000000000000000001
11111111 8 -1 32 11111111111111111111111111111111
Sign vs Zero Extension

Sign Extension vs Zero Extension

Sign extension

Copies the original sign bit into new high-order positions. Used when widening signed two’s-complement values.

Zero extension

Fills all new high-order positions with zero. This is normally used when widening unsigned binary values.

Same 8-bit pattern, different extension rule Comparison
Original: 11111011 As signed 8-bit: -5 Sign extended to 16 bits: 1111111111111011 = -5 Zero extended to 16 bits: 0000000011111011 = 251 Same original bits. Completely different meaning.
Two’s Complement

Why Sign Extension Preserves the Signed Value

In an n-bit two’s-complement number, the highest bit has a negative positional weight of −2n−1. Extending the sign bit changes the apparent contribution of the old leading bit, but the newly inserted leading 1 bits contribute exactly the amount required to preserve the original negative value.

For positive values, sign extension is simpler because the sign bit is zero. Adding more leading zeros does not change the unsigned magnitude or the signed interpretation.

Sign extension is meaningful only when the source bit pattern is being interpreted as a signed two’s-complement value. For unsigned values, zero extension is generally the appropriate widening operation.
Width Rules

Source Width and Target Width Requirements

The target width must be greater than or equal to the source width. Sign extension is a widening operation; it does not remove bits.

If the source and target widths are identical, no new sign bits need to be added and the binary pattern remains unchanged.

Reducing a bit width is not sign extension. That operation is truncation and can change the value if significant high-order bits are discarded.

Operation Example Meaning
8 → 16 Valid Standard sign extension
16 → 32 Valid Standard sign extension
32 → 64 Valid Standard sign extension
8 → 8 No change Value already has requested width
16 → 8 Not sign extension This would require truncation
Programming

Where Sign Extension Appears in Computing

Sign extension is common anywhere a smaller signed integer is converted to a larger signed representation. CPUs, compilers, programming languages, binary decoders, instruction sets, embedded firmware, and data protocols frequently perform this operation.

CPU Signed load and widening instructions
Compilers Integer promotions and signed conversions
Protocols Decoding signed fields smaller than host integers
Embedded Sensor registers and packed binary values
Practical Example

Sign Extending an 8-Bit Sensor Reading

Suppose an embedded sensor returns one signed byte and the raw register value is 11110110. As an 8-bit two’s-complement integer, the value is −10.

If software needs to place that value in a 16-bit signed variable, the correct representation is:

Sensor byte widening 8 → 16
8-bit register: 11110110 Sign bit: 1 16-bit sign extension: 1111111111110110 Signed decimal: -10
Common Mistakes

Binary Sign Extension Errors to Avoid

Filling negative values with zeros

This changes the sign and value. A negative two’s-complement number must be extended using leading ones.

Ignoring the original width

The same binary digits can have different signed meanings depending on the bit width. The source width therefore needs to be known before the signed value can be interpreted correctly.

Confusing sign extension with padding

Ordinary visual padding may add zeros for readability. Sign extension is a numeric operation and repeats the actual sign bit.

Using sign extension for unsigned numbers

Unsigned binary values normally use zero extension because their most significant bit is part of the magnitude rather than a sign indicator.

FAQ

Binary Sign Extension Calculator FAQs

Common questions about sign bits, two’s complement, binary widening, source widths, target widths, and signed integer conversions.

Sign extension increases the width of a signed two’s-complement value by copying its sign bit into each newly added high-order bit.
In two’s-complement representation, the leftmost bit determines the sign. Repeating it preserves the signed numeric value when the width increases.
Add eight copies of the original sign bit to the left side of the 8-bit value. Use zeros when the sign bit is 0 and ones when it is 1.
The value is nonnegative, so sign extension adds zeros to the left.
The two’s-complement value is negative, so the new high-order bits are filled with ones.
No. Correct sign extension preserves the original signed decimal value.
Sign extension copies the sign bit and is used for signed values. Zero extension always adds zeros and is normally used for unsigned values.
Yes. 8-bit -1 is 11111111. Extending the sign bit to 32 bits produces 11111111111111111111111111111111, which remains -1.
No. Reducing width is truncation, not sign extension, and it may change the value.
It is the sign bit when the pattern is interpreted as a fixed-width signed two’s-complement integer. For unsigned data, it is simply part of the magnitude.
Yes. The original 16-bit sign bit is repeated sixteen times to create a 32-bit signed representation.
Yes. The sign-extension calculation runs directly in your browser.
Scroll to Top