Integer (computer science)
In computer science, the term
integer is used to refer to any\n
data type which can represent some subset of the mathematical\n
integers. These are also known as
integral data types.
Value and Representation
The value of a datum with an integral type is the mathematical\ninteger that it corresponds to. The representation of this datum\nis the way the value is stored in the computer’s memory. Integral\ntypes may be unsigned (capable of representing only non-negative\nintegers) or signed (capable of representing negative integers as\nwell).
The most common representation of a positive integer is a string of\nbits, using the binary numeral system. The order of the bits\nvaries; see Endianness. The width or precision of an\nintegral type is the number of bits in its representation. An integral type with n bits can encode 2n numbers; for example an unsigned type typically represents the non-negative values 0 through 2n−1.
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 −2(n−1) through 2(n−1)−1. Two’s 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 is still commonly used in mainframe financial applications and in databases.
Common integral data types
\n| 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 |
\n
Different CPUs support different integral data types. Typically,\nhardware will support both signed and unsigned types but only a small,\nfixed set of widths.
The table above lists integral type widths that are supported in hardware by common processors. High level programming languages provide more possibilities. It is common to have a ‘double width’ integral type that has twice as many bits as the biggest hardware-supported type. Many languages also have
bit-field types (a specified number of bits, usually constrained to be less than the maximum hardware-supported width) and
range types (which can represent only the integers in a specified range).
Some languages, such as
Lisp and
REXX, support
arbitrary precision integers (also known as ‘infinite precision integers’ 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 or Flag type is a special range type that can represent only two values: 0 and 1, usually 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 of addressing.
A four-bit quantity is known as a
nibble (when eating being smaller than a
bite) or
nybble (being a pun on the form of the word
byte). One nibble corresponds to one digit in
hexadecimal and binary-coded decimal.
Pointers
A pointer is often, but not always,\nrepresented by an integer of specified width. This is often, but not\nalways, the widest integer that the hardware supports directly. The\nvalue of this integer is the
memory address of whatever the\npointer points to.
Bytes and octets
The term byte initially meant ‘the least addressable unit of\nmemory’. In the past, 5-, 6-, 7-, 8-, and 9-bit bytes have all been\nused. There have also been computers that could address individual\nbits (‘bit-addressed machine’), or that could only address 16- or\n32-bit quantities (‘word-addressed machine’). The term byte was usually not used at all in connection with bit- and word-addressed machines.
The term octet always refers to an 8-bit quantity. It is mostly\nused in the field of computer networking, where computers with\ndifferent byte widths might have to communicate.
In modern usage
byte almost invariably means eight bits, since all other\nsizes have fallen into disuse;
octet has thus come to be synonymous\nwith
byte.
Bytes are used as the
unit of
computer memory of\nall kinds. One might speak of a 50-byte text string, a 100 kB (kilobyte)\nfile, a 128 MB (megabyte)
RAM module, or a 30 GB (gigabyte)
hard disk.\nThe prefixes used for byte measurements are similar to the\n
SI prefixes used for other measurements, but they do not have the\nsame meanings (see
binary prefix for further discussion).
\n| Prefix | Name | Usual (SI) meaning | Meaning when applied to bytes\n |
|---|
| k, K | kilo | 103 = 1000 | 210 = 1024\n |
| M | mega | 106 = 10002 | 220 = 10242\n |
| G | giga | 109 = 10003 | 230 = 10243\n |
| T | tera | 1012 = 10004 | 240 = 10244\n |
| P | peta | 1015 = 10005 | 250 = 10245\n |
Unscrupulous
hard disk manufacturers describe their products using\nthe power-of-1000 meanings, which is the subject of a
current false advertising lawsuit.
Words
The term word initially was equivalent to ‘the logical size of an address of a location in the system memory’, and was thus CPU- and OS-specific. One could say that the
IBM 360 had 32-bit words (even though its addresses were limited to 24 bits), 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,
quadword, and
halfword, also vary with the CPU and OS.
Currently (
2004) 32-bit word sizes are most common among general-purpose computers, with 64-bit machines 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.
\nCategory:Computer terminology\n\n