Signed and unsigned integers

From Glitch City Wiki
(Redirected from Unsigned)
Jump to navigation Jump to search

Signed integers and unsigned integers are two different terms in computing.

When representing a number in computing, it is stored as a sequence of bits (binary) or bytes (hexadecimal).

In order for a computer to represent both a positive or negative number, the hardware may use what is called a signed integer.

Signed integers may use one half of the range of values as negative, and the other half of the range of values as positive.

Conversely, unsigned integers cannot include both positive and negative integers, and what would be a negative number could be interpreted as a positive number, especially one that is very large (such as 65535 for a two byte value).

Both signed and unsigned integers sometimes come into play in glitches.

Unsigned integer examples

The experience underflow glitch in Pokémon Red, Blue, and Yellow and Pokémon Gold, Silver and Crystal exploits both the fact that a Pokémon's experience is an unsigned number, and that a Pokémon (especially a Level 1 or Level 0 'medium-slow' growth rate Pokémon) can be forced to have 'negative' (but effectively a little less than 16777076) total experience.

The Pomeg glitch in Pokémon Emerald involves a Pokémon's HP underflowing from 0 to 65535 or below. A Pokémon's HP is stored in two bytes, hence when the game subtracts 1 from 0, it brings up a value represented as: (2^16-1) or 65535.

Signed integer examples

Giratina 'gaining' negative stats

Through the use of the Giratina Origin Forme glitch in Pokémon Platinum, it is possible to see negative stat gains, even though the display of only positive stat gains are possible in regular gameplay.