Primitive Datatypes
In computing primitive datatypes make the base of all more complex data structures. Each of them does nothing more than storing numbers. They just differ by size and interpretation.
The size is highly dependant by the type. The maximung lenght of a primitive type is limited by the hardware. For instance, an 8-bit machine may only operate with numbers that do not exceed 8 bits in length. Exceptions may apply such as the RP2A03 processor used as central processing unit in the NES which is able to exceed this limit in address handling.
Modern systems are based on a 64-bit architecture and can handle huge numbers in general. But since we are interested in hacking games of any generation it is meaningful being aware of all primitive datatypes and their limits!
Integers
Integers describe either positive or negative natural numbers with no fraction. There's two types of integers: Signed and unsigned integers. By default integers are signed meaning their range is half negative and have positive including 0.
Unsigned integers only can be positive but can be twice as big as their signed counterpart.
The table below represents all common integer types.
Name | Size | Min (dec) | Max (dec) |
---|---|---|---|
char/byte | 8 bits | -128 | 127 |
unsigned char/byte | 8 bits | 0 | 255 |
short | 16 bits | –32.768 | 32.767 |
unsigned short | 16 bits | 0 | 65.535 |
int | 32 bits | -2,147,483,648 | 2,147,483,647 |
unsigned int | 32 bits | 0 | 4.294.967.295 |
long/long long | 64 bits | -9,223,372,036,854,775,808 | 9,223,372,036,854,775,807 |
unsigned long/long long | 64 bits | 0 | 18.446.744.073.709.551.615 |
Booleans
A boolean value only knows two states: true or false. False can be seen as a representation of 0 or off and true as 1 or on. One might think since only 2 values are possible a boolean may only occupy one bit in memory, but infact, it occupies an entire byte (8 bits) since 1 byte is the smallest addressable value. But it is still possible to store 8 booleans withing a single byte. One bit's state can be checked with boolean operators such as AND or OR. This mechanism is called a DIP Switch. The entire concept of DIP Switches will be explained separately.
Name | Size | Min | Max |
---|---|---|---|
bool/boolean | 8 bits | false (0) | true (1) |
Floating Point Numbers
Floating point numbers are used to represent numbers with a fraction. In computing this is done via a floating point arithmetic. A floating point value consists of mantissa, exponent and the sign bit. In modern computing highly precise floating point types are used. Smaller/less precise formats are less commonly used, moslty for educational porpuses. Since all floats have a sign flag, all types of floats can also be negative. Value like -0 (minus zero) and -Infinite (minus infinite) exist as well. A small range is not usable and defined as NaN (not a number).
Name | Size | depricated | Max abs. | Min abs. w/o 0 |
---|---|---|---|---|
mini | 8 bits | yes | 15360 | 0.125 |
mini/half/bitfloat16 | 16 bits | yes | 65,504 | 0.0000000596 |
float/single/decimal32 | 32 bits | no | 3.4e38 | 1.40e-45 |
double/decimal64 | 64 bits | no | 1.797e308 | 4.941e-324 |
Extended Precision | 80 bits (x86) | no | 1.18e4932 | 3.65e−4951 |
decimal (C#) | 128 bits | no | 7.92e28 | 1e-28 |
This table only covers the most significant float types regarding understanding, game hacking and basic programming. Many more exist.