Table of contents |
2 Common integral data types 3 Pointers 4 Bytes and Octets 5 Words |
The value of a datum with an integral type is the mathematical integer that it corresponds to. The representation of this datum is the way the value is stored in the computer's memory. Integral types may be unsigned (capable of representing only nonnegative integers) or signed (capable of representing negative integers as well).
The most common representation of a positive integer is a string of bits, using the binary numeral system. The order of the bits varies; see Endianness. The width or precision of an integral type is the number of bits in its representation. An unsigned integral type with n bits can represent numbers from 0 to .
There are three different ways to represent negative numbers in a binary numeral system. The most common is two's complement, which allows a signed integral type with n bits to represent numbers from to . Twos complement arithmetic is convenient because there is a perfect one-to-one correspondence between representations and values, and because addition and subtraction do not need to distinguish between signed and unsigned types. The other possibilities are sign-magnitude and one's complement.
Another, rather different representation for integers is binary-coded decimal, which was once commonly used (notably in financial applications) but is now rare.
bits | name | range | uses |
---|---|---|---|
8 | byte, octet | Signed: -128 to +127 Unsigned: 0 to +255 | ASCII characters, C char (minimum), Java byte |
16 | word | Signed:-32,768 to +32,767 Unsigned: 0 to +65,535 | UCS-2 characters, C short int (minimum), C int (minimum), Java char, Java short int |
32 | word, doubleword, longword | Signed:-2,147,483,648 to +2,147,483,647 Unsigned: 0 to +4,294,967,295 | UCS-4 characters, C int (usual), C long int (minimum), Java int |
64 | longword, quadword | Signed:-9,223,372,036,854,775,808 to +9,223,372,036,854,775,807 Unsigned: 0 to +18,446,744,073,709,551,615 | C long int (on 64-bit machines), C99 long long int (minimum), Java long int |
Some languages, such as Lisp, support arbitrary precision integers (also known as "infinite precision" or "bignums"). These use as much of the computer's memory as is necessary; however, the computer only has a finite amount of storage, so they too can only represent a finite subset of the mathematical integers.
A Boolean type is a special range type that can represent only two values: 0 and 1, identified with false and true respectively. This type can be stored in memory using a single bit, but is often given a full byte for convenience.
A four-bit quantity is known as a nybble or nibble; this is a joke on the word "byte". One nybble corresponds to one digit in hexadecimal and binary-coded decimal.
A pointer is often, but not always, represented by an integer of specified width. This is often, but not always, the widest integer that the hardware supports directly. The value of this integer is the memory address of whatever the pointer points to.
The term octet always refers to an 8-bit quantity. It is mostly used in the field of computer networking, where computers with different byte widths might have to communicate.
In modern usage "byte" invariably means eight bits, since all other sizes have fallen into disuse; "octet" has thus come to be synonymous with "byte".
Bytes are used as the unit of computer memory of all kinds. One speaks of a 50 byte text string, a 100 kB (kilobyte) file, a 128 MB (megabyte) RAM module, a 30 GB (gigabyte) hard disk. The prefixes used for byte measurements are similar to the SI prefixes used for other measurements, but they do not have the same meanings (see binary prefix for further discussion).
Prefix | Name | Usual (SI) meaning | Meaning when applied to bytes |
---|---|---|---|
k, K | kilo | 10^{3} = 1000 | 2^{10} = 1024 |
M | mega | 10^{6} = 1000^{2} | 2^{20} = 1024^{2} |
G | giga | 10^{9} = 1000^{3} | 2^{30} = 1024^{3} |
T | tera | 10^{12} = 1000^{4} | 2^{40} = 1024^{4} |
P | peta | 10^{15} = 1000^{5} | 2^{50} = 1024^{5} |
Unscrupulous hard disk manufacturers describe their products using the power-of-1000 meanings, which is the subject of a current false advertising lawsuit.
The term word initially meant "the size of an address in the system memory", and was thus CPU- and OS-specific. One could say that the IBM 370 had 32-bit words, and the 8086 had 16-bit words. Many different word sizes have been used, including 6-, 8-, 12-, 16-, 18-, 24-, 32-, 36-, 60- and 64-bit. The meanings of terms derived from "word", such as "longword", "doubleword", and "halfword", also vary with the CPU and OS.
Currently 32-bit word sizes are most common among general-purpose computers, with 16-bit dying out and 64-bit used mostly for large installations. Embedded processors with 8- and 16-bit word size are still common. Word sizes that aren't a multiple of 8 have vanished along with non-8-bit bytes.