Tutorials:Value types

From Cheat Engine
Revision as of 08:45, 18 March 2017 by TheyCallMeTim13 (talk | contribs) (Created page with 'In memory there really are no types, all value types are stored with bytes. It's more how the process uses the values that dictates it's type. Now the format for some types is a …')
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search

In memory there really are no types, all value types are stored with bytes. It's more how the process uses the values that dictates it's type. Now the format for some types is a lot different, like in an integer 1 is 0x1 but in an ASCII string 1 is 0x31 (values written in a 0x* notation are in hexadecimal format).

Bits, Bytes, and Words

A bit is a binary digit. So a bit is a zero or a one. Bits are implemented in computer hardware using switches. If the switch is closed (on) then the bit is one and if the switch is open (off) then the bit is zero. A bit is limited to representing two values, since it's a base two.

Since the English alphabet contains more than two letters, a letter cannot be represented by a bit. A byte is a sequence of bits. Since the mid 1960's a byte has been 8 bits in length. 01000001 is an example of a byte. Since there are 8 bits in a byte there are 28 different possible sequences for one byte, ranging from 00000000 to 11111111. This means that a byte can be used to represent any type of value with no more than 28 = 256 possible values. Since the number of things that you can enter on a computer keyboard is smaller than 256 (including all key stoke pairs, like shift or control plus another key), a code for a key stoke is represented with a code within a byte.[1]

Note: Unicode was introduced to handle multiple languages, and is based on ASCII.
Side note: ASCII was based on telegraph code, and started out as a 7 bit system.

Now you will tend to hear that all values are stored in hexadecimal format, but really it's that all computers will convert the stored binary to hexadecimal when displaying the data else it's alway binary bits (until quantum computers are standard).

Note: Hexadecimal is just a base 16 number system, decimal is a base 10, and binary is a bass 2.

So bytes are like the base data units, and we can store any ASCII character in a byte. Now the smallest possible word, being 2 characters, is 2 bytes so this value type got the nomenclature of word or WORD (this was the main value type in 16 bit systems). Then came 32 bit and the 4 byte registers so the 4 byte value type got the nomenclature of double word or DWORD. And with 64 bit came the 8 byte value type, the quad word or QWORD. There is also the TWORD (Ten byte, 10 bytes, 80 bit), OWORD (Octoword, 16 bytes, 128 bit), YWORD (Based on the YMM registers, 32 bytes, 256 bit), ZWORD (Based on the ZMM registers, 64 bytes, 512 bit).


Signs

In memory there is no direct way to represent a negative number, this is done in varying ways to simplify the arithmetic.

An unsigned byte (not allowing negative numbers) can hold 0 to 255, while a signed byte (allowing negative numbers) can hold -128 to 127.[2]


Floating points

In memory there are no fractions nor decimal points, but a floating decimal point system was setup. It uses an approximation so as to support a trade-off between range and precision. Now there are other ways of representing a fractional numbers like fixed point, binary coded decimal, or logarithmic number systems. But the floating point representation is by far the most common way of representing an approximation of real numbers in a computer's memory, but there are both single and double precision floating points.[3]


Value sizes

So these are the standard value sizes:

Bit
A binary digit, the smallest unit of data in a computer's memory.
Byte
A group bits (usually eight), operated on as a unit.
WORD - Word
2 Bytes (16 bits).
DWORD - Double word
4 Bytes (32 bits).
QWORD - Quadword
8 Bytes (64 bits).

These are some of the larger sizes:

TWORD - Ten byte
10 Bytes (80 bits).
OWORD - Octoword
16 Bytes (128 bits).
YWORD
32 Bytes (256 bits).
ZWORD
64 Bytes (512 bits).


Value types

So these are the standard value types:

Bit
Unsigned integer.
Byte
(Un)signed integer.
2 byte - WORD
(Un)signed integer.
4 Bytes - DWORD
(Un)signed integer.
8 Bytes - QWORD
(Un)signed integer.
Float - DWORD
Single precision floating point.
Double - QWORD
Double precision floating point.
Text / String
A string of text characters (any length). Can be ASCII or Unicode (wide) encoded.
Array of bytes / AOB
An array of bytes (any length).
Represented as a string of bytes.


Going further


Sources

  1. www.cs.scranton.edu/~cil102/data_bits.html
  2. wikipedia.org/wiki/Signed_number_representations
  3. wikipedia.org/wiki/Floating-point_arithmetic