Checking signed and unsigned extension of a bit pattern
Widening the eight-bit pattern FF to sixteen bits gives FFFF with sign extension and 00FF with zero extension. Those mean negative 1 and positive 255.
One pattern, two ways to widen it
An eight-bit pattern is just eight binary digits. What it means depends on a convention. Read as an unsigned number, FF in hexadecimal is 255. Read as a signed two's-complement number, the same pattern is negative 1. When the pattern is copied into a sixteen-bit space, the new upper bits have to be filled. Filling them with copies of the top bit is sign extension and preserves the signed value. Filling them with zeroes is zero extension and preserves the unsigned value. The worked cases show both, using the integer base converter to read the patterns and the basic calculator for the signed adjustment.
Sign extension of FF
The top bit of FF is 1, so sign extension fills the upper eight bits with ones, giving FFFF. Read as an unsigned sixteen-bit number, FFFF is 65,535, which the converter returns when you convert FFFF from base 16 to base 10. To interpret it as signed, subtract 2 to the sixteenth power, 65,536, from any value of 32,768 or more. Here 65,535 minus 65,536 is negative 1. The signed value stayed the same through the widening, from negative 1 in eight bits to negative 1 in sixteen. That is the purpose of sign extension.
Zero extension of FF
Zero extension fills the upper eight bits with zeroes, giving 00FF. The converter reads 00FF in base 16 as 255, because leading zeroes do not change an unsigned value. The pattern that meant negative 1 as an eight-bit signed number now means positive 255 as a sixteen-bit number, whether you treat it as signed or not, since the top bit is 0. So zero extension of a signed negative value changes its meaning. It is correct only when the original was an unsigned quantity, such as a byte of pixel brightness or a character code.
Ranges of signed values
An n-bit two's-complement number covers the range from negative 2 to the power n minus 1 up to 2 to the power n minus 1, minus 1. For 8 bits that is negative 128 to 127, and for 16 bits it is negative 32,768 to 32,767. Unsigned ranges start at zero and end at 2 to the power n, minus 1: 0 to 255 for 8 bits and 0 to 65,535 for 16 bits. The pattern 80 in eight bits is negative 128 signed and 128 unsigned. Sign extension makes it FF80, which is 65,408 unsigned and, after subtracting 65,536, negative 128 signed. Zero extension gives 0080, which is positive 128.
Patterns that behave the same either way
When the top bit is 0, both extensions give the same result. The pattern 7F is 127 in eight bits, and extending it gives 007F, which is 127 in sixteen bits under either rule. The two methods differ only for patterns with a top bit of 1, which are the negative values under the signed convention. That is why a bug caused by the wrong extension can lie hidden for a long time and appear only when a negative value or a byte of 128 or more first arrives. Test inputs should include a value on each side of the sign boundary. A short example shows the risk. A temperature sensor sends one byte, and the value 0xFB means negative 5 degrees as a signed byte. A program that zero-extends it reads 251 degrees, and a program that sign-extends reads negative 5. Both programs handle 0x14, which is 20, identically, so ordinary testing in a warm room would never reveal the difference. The converter shows the unsigned reading, 251 for FB, and the subtraction of 256 gives the signed one.
Where the choice shows up in software
Many programming languages and processors make the choice explicit. When a signed 8-bit integer is promoted to a wider signed type, the compiler sign-extends. When an unsigned byte is promoted, it zero-extends. Processor instruction sets provide separate instructions for loading with sign extension and with zero extension, such as MOVSX and MOVZX on x86. Mixing the types by accident, for example reading a signed byte into an unsigned wide variable, produces values like 65,535 where negative 1 was intended. Knowing the declared type of the source is what settles the question.
What a bare hexadecimal token does not say
The text FF alone carries no width and no signedness. It could be 255 unsigned, negative 1 signed in 8 bits, or the low byte of a longer number. The text FFFF could be 65,535 or negative 1 depending on the field. Documents that list register values or protocol fields therefore specify the width and the interpretation together, for example as an int8 or a uint16. When you receive raw hex, ask for both pieces of information before converting it to decimal, since the decimal answer changes with each assumption.
Using the integer base converter
The converter takes a digit string, a source base and a target base from 2 to 36, and returns the integer in the target base. It works with arbitrary-precision integers, so it does not wrap at 8, 16 or 32 bits. The output for FFFF is the plain positive integer 65,535, and the signed interpretation is left to you. Subtracting 2 to the power of the field width, as in the worked case, is the manual step that turns an unsigned reading into a signed one. The same converter can show binary strings such as 11111111 as 255. Entering the digits one field at a time keeps the base explicit: the string 80 means 128 in base 16 but 80 in base 10, and a pattern of 0s and 1s is read in base 2. Choose the source base from the notation in the specification, such as a 0x prefix for hexadecimal, and convert to decimal only after the width and signedness are known. For a full conversion workflow, convert the unsigned reading first, then apply the signed adjustment by hand.
Other encodings extend differently
The cases cover one eight-bit pattern and its sixteen-bit extensions under the two's-complement convention. Other signed encodings, such as sign-magnitude or ones' complement, extend differently and are not discussed. Floating-point values, bit fields with mixed meaning and endianness (byte order) are also outside the example. Keep the source specification beside any conversion, so the width and signedness are recorded where a later reader can find them.
Reproduce the checks
Sixteen-bit pattern as unsigned
Open the Integer Base Converter and enter:
- Value
FFFF- Source base
16- Target base
10
Expected output:
Value
65535The signed interpretation still needs the specified width.
Signed sixteen-bit value
Open the Basic calculator and enter:
- First number
65535- Operation
subtract- Second number
65536
Expected output:
Result
-1The extension preserves the negative value.
Zero-extended pattern
Open the Integer Base Converter and enter:
- Value
00FF- Source base
16- Target base
10
Expected output:
Value
255Leading zeroes preserve the unsigned value instead.
References and implementation scope
The examples describe the behavior of the linked Computandum tools. A successful local check does not establish that another application accepts the same format or applies the same limits.
Sources
- Primary definition and convention reference ↗ · 2026-10-08