Home

signextended

Signextended refers to the process of enlarging the width of a signed integer by replicating its sign bit into all higher-order bits. In two's complement representation, this preserves the numeric value when promoting from a smaller width to a larger width. If the original value's most significant bit is 0, the new bits are filled with 0s; if it is 1, the new bits are filled with 1s.

Common cases include sign-extending an 8-bit value to 16, 32, or 64 bits, or sign-extending a 16-bit

Sign extension is the counterpart of zero extension, which fills new higher-order bits with zeros regardless

Hardware and software implementations provide mechanisms for sign extension. Some CPUs offer dedicated instructions for sign-extending

See also: sign extension, two's complement, sign bit, type promotion.

value
to
32
or
64
bits.
For
example,
the
8-bit
value
0x7F
sign-extends
to
0x007F
in
16
bits,
while
0x80
sign-extends
to
0xFF80
in
16
bits.
A
32-bit
value
0x80000000
sign-extends
to
0xFFFFFFFF80000000
in
64-bit
form.
of
the
sign.
Sign
extension
is
usually
required
when
performing
arithmetic
across
mixed-width
operands,
when
promoting
smaller
integers
to
larger
types,
or
when
loading
signed
immediates
from
memory.
smaller
operands
(for
example,
sign-extend
byte
or
halfword
instructions
in
certain
ISAs;
and
move-with-sign-extension
instructions
in
x86).
Compilers
perform
sign
extension
implicitly
during
type
promotion
in
high-level
languages.