Science  People  Locations  Timeline
Index: A B C D E F G H I J K L M N O P Q R S T U V W X Y Z

Home > Integer (computer science)


 Contents
In computer science, the term integer is used to refer to any data type which can represent some subset of the mathematical integers. These are also known as integral data types.

1 Value and Representation

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 non-negative 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 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 twos 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 ones complement .

Another, rather different, representation for integers is binary-coded decimal, which is still commonly used in mainframe financial applications and in databases.

2 Common integral data types

bitsnamerangeuses
8 byte, octetSigned: −128 to + 127
Unsigned: 0 to +255
ASCIIASCII A merican S tandard C ode for I nformation I nterchange , generally pronounced 'aski', is a character set and a character encoding based on the Roman alphabet as used in modern English and other Western European languages. It is most commonly used b characters, C char (minimum), Java byte
16wordSigned: −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
32word, doubleword, longwordSigned: −2,147,483,648 to + 2,147,483,647299e09 2147483647 2,147,483,647 is an integer which is a Mersenne prime , and is the largest number that can fit into a signed ( two's complement) 32-bit signed integer on a computer. 2147483647 Cardinal two billion, one hundred [and] forty-seven million,
Unsigned: 0 to +4,294,967,295
UCS-4 characters, C int (usual), C long int (minimum), Java int
64longword, quadwordSigned: −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
128 Signed: −170,141,183,460,469,231,731,687,303,715,884,105,728 to +170,141,183,460,469,231,731,687,303,715,884,105,727
Unsigned: 0 to +340,282,366,920,938,463,463,374,607,431,768,211,455
C int __attribute__ ((mode(TI))) (on 64-bit machines using gcc)

Different CPUs support different integral data types. Typically, hardware will support both signed and unsigned types but only a small, fixed 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 LispLisp is a family of functional programming languages with a long history. Developed first as an abstract notation for recursive functions, it later became the favored language of artificial intelligence research during the field's heyday in the 1970s and and REXXREXX (Restructured Extended Executor) is a programming language which was developed at IBM, and several implementations are available under open source licenses. It is a structured high-level programming language which was designed to be both easy to lear, support arbitrary precision integers (also known as infinite precision integers or bignums). These use as much of the computer’s memory as is necessary to store the numbers; however, a 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 type which 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 and speed of access.

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 holds one digit or a sign code in binary-coded decimal.



Read more »

Non User