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.
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.
How to Sign Extend a Binary Number
Sign Extending a Positive Binary Number
Consider the signed 8-bit value 01100101. Its sign bit is 0,
so it represents a nonnegative number.
Because the sign bit is zero, the eight additional high-order bits are also zeros. The extended representation still represents decimal 101.
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.
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.
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 Extension vs Zero Extension
Copies the original sign bit into new high-order positions. Used when widening signed two’s-complement values.
Fills all new high-order positions with zero. This is normally used when widening unsigned binary values.
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.
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 |
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.
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:
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.
Binary Sign Extension Calculator FAQs
Common questions about sign bits, two’s complement, binary widening, source widths, target widths, and signed integer conversions.