Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Integer (computer science)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{short description|Datum of integral data type}} In computer science, an '''integer''' is a [[datum]] of '''integral data type''', a [[data type]] that represents some [[interval (mathematics)|range]] of mathematical [[integer]]s.<ref>https://www.oxfordreference.com/display/10.1093/acref/9780199688975.001.0001/acref-9780199688975-e-2612?rskey=er6iE8&result=2905</ref> Integral data types may be of different sizes and may or may not be allowed to contain negative values. Integers are commonly represented in a computer as a group of [[binary digit]]s (bits). The size of the grouping varies so the set of integer sizes available varies between different types of computers. Computer hardware nearly always provides a way to represent a processor [[word size|register]] or memory address as an integer. == Value and representation == The ''value'' of an item with an integral type is the mathematical integer that it corresponds to. Integral types may be ''unsigned'' (capable of representing only non-negative integers) or ''signed'' (capable of representing negative integers as well).<ref>{{cite web |url=http://www.swarthmore.edu/NatSci/echeeve1/Ref/BinaryMath/NumSys.html |title=Representation of numbers |last=Cheever |first=Eric |publisher=Swarthmore College |access-date=2011-09-11}}</ref> An integer value is typically specified in the [[source code]] of a program as a sequence of digits optionally prefixed with + or β. Some programming languages allow other notations, such as hexadecimal (base 16) or octal (base 8). Some programming languages also permit [[digit group separator]]s.<ref>{{cite web|author=Madhusudhan Konda |url=http://radar.oreilly.com/2011/09/java7-features.html |title=A look at Java 7's new features - O'Reilly Radar |publisher=Radar.oreilly.com |date=2011-09-02 |access-date=2013-10-15}}</ref> The ''internal representation'' of this datum is the way the value is stored in the computer's memory. Unlike mathematical integers, a typical datum in a computer has some minimal and maximum possible value. The most common representation of a positive integer is a string of [[bit]]s, using the [[binary numeral system]]. The order of the memory [[byte]]s storing the bits varies; see [[endianness]]. The ''width'', ''precision'', or ''bitness''<ref>{{Cite book |last=Barr |first=Adam |url=https://books.google.com/books?id=BxdxDwAAQBAJ&dq=%22bitness%22&pg=PA268 |title=The Problem with Software: Why Smart Engineers Write Bad Code |date=2018-10-23 |publisher=MIT Press |isbn=978-0-262-34821-8 |language=en}}</ref> of an integral type is the number of bits in its representation. An integral type with ''n'' bits can encode 2<sup>''n''</sup> numbers; for example an unsigned type typically represents the non-negative values 0 through {{nowrap|2<sup>''n''</sup> β 1}}. Other encodings of integer values to bit patterns are sometimes used, for example [[binary-coded decimal]] or [[Gray code]], or as printed character codes such as [[ASCII]]. There are four well-known [[signed number representations|ways to represent signed numbers]] in a binary computing system. The most common is [[two's complement]], which allows a signed integral type with ''n'' bits to represent numbers from {{nowrap|β2<sup>(''n''β1)</sup>}} through {{nowrap|2<sup>(''n''β1)</sup> β 1}}. Two's complement arithmetic is convenient because there is a perfect [[one-to-one correspondence]] between representations and values (in particular, [[signed zero|no separate +0 and β0]]), and because [[addition]], [[subtraction]] and [[multiplication]] do not need to distinguish between signed and unsigned types. Other possibilities include [[offset binary]], [[sign-magnitude]], and [[ones' complement]]. Some computer languages define integer sizes in a machine-independent way; others have varying definitions depending on the underlying processor word size. Not all language implementations define variables of all integer sizes, and defined sizes may not even be distinct in a particular implementation. An integer in one [[programming language]] may be a different size in a different language, on a different processor, or in an execution context of different bitness; see {{Section link||Words}}. Some [[Decimal computer|older computer architectures]] used decimal representations of integers, stored in [[binary-coded decimal|binary-coded decimal (BCD)]] or other format. These values generally require data sizes of 4 bits per decimal digit (sometimes called a [[nibble]]), usually with additional bits for a sign. Many modern CPUs provide limited support for decimal integers as an extended datatype, providing instructions for converting such values to and from binary values. Depending on the architecture, decimal integers may have fixed sizes (e.g., 7 decimal digits plus a sign fit into a 32-bit word), or may be variable-length (up to some maximum digit size), typically occupying two digits per byte (octet). == Common integral data types == {| class="wikitable" |- ! rowspan="2" | Bits ! rowspan="2" | Name ! rowspan="2" | Range (assuming [[two's complement]] for [[Signed number representations|signed]]) ! rowspan="2" | Decimal digits ! rowspan="2" | Uses ! colspan="8" scope="col" | Implementations |- ! [[C (programming language)|C]]/[[C++]] ! [[C Sharp (programming language)|C#]] ! [[Pascal (programming language)|Pascal]] and [[Delphi (programming language)|Delphi]] ! [[Java (programming language)|Java]] ! [[SQL]]{{efn |name=notesqla |Not all SQL dialects have unsigned datatypes.<ref name=SybDT>{{cite web|url=http://infocenter.sybase.com/help/index.jsp?topic=/com.sybase.infocenter.dc36271.1550/html/blocks/blocks20.htm |title=Sybase Adaptive Server Enterprise 15.5: Exact Numeric Datatypes}}</ref><ref name=MySQLDT>{{cite web|url=http://dev.mysql.com/doc/refman/5.6/en/numeric-types.html |title=MySQL 5.6 Numeric Datatypes}}</ref>}} ! [[FORTRAN]] ! [[D (programming language)|D]] ! [[Rust (programming language)|Rust]] |- | rowspan="2" style="text-align: right;" | 4 | rowspan="2" | [[nibble]], semioctet | ''[[Signed number representations|Signed:]]'' From β8 to 7, from β(2<sup>3</sup>) to 2<sup>3</sup> β 1 | style="text-align: right;" | {{#expr:3*ln2/ln10 round 2}} | rowspan="2" | [[Binary-coded decimal]], single decimal digit {{shy|repre|sen|ta|tion}} | colspan="8" rowspan="2" style="text-align: center; background: #eaecf0;" | — |- | ''Unsigned:'' From 0 to 15, which equals 2<sup>4</sup> β 1 | style="text-align: right;" | {{#expr: 4 * ln(2) / ln(10) round 2}} |- | rowspan="2" style="text-align:right;"| 8 | rowspan="2" | [[byte]], [[octet (computing)|octet]], i8, u8 | ''Signed:'' From β128 to 127, from β(2<sup>7</sup>) to 2<sup>7</sup> β 1 | style="text-align: right;" | {{#expr: 7 * ln(2) / ln(10) round 2}} | rowspan="2" | [[ASCII]] characters, [[code unit]]s in the [[UTF-8]] [[character encoding]] | {{mono|int8_t}}, {{mono|signed char}}{{efn|name=notescb|garbage=8 char}} | {{mono|sbyte}} | {{mono|Shortint}} | {{mono|byte}} | {{mono|tinyint}} | {{mono|INTEGER}}{{efn|name=fortran|Fortan uses 'kinds' to control the size of integers. Parameterized constants defining the available kinds are available in the iso_fortran_env intrinsic module. Constants defining C compatible kinds are available in the iso_c_binding intrinsic module.}} | {{mono|byte}} | {{mono|i8}} |- | ''Unsigned:'' From 0 to 255, which equals 2<sup>8</sup> β 1 | style="text-align: right;" | {{#expr: 8 * ln(2) / ln(10) round 2}} | {{mono|uint8_t}}, {{mono|unsigned char}}{{efn|name=notescb|garbage=8 char}} | {{mono|byte}} | {{mono|Byte}} | {{n/a}} | {{mono|unsigned tinyint}} | {{n/a}} | {{mono|ubyte}} | {{mono|u8}} |- | rowspan="2" style="text-align: right;" | 16 | rowspan="2" | halfword, [[Word (data type)|word]], short, i16, u16 | ''Signed:'' From β32,768 to 32,767, from β(2<sup>15</sup>) to 2<sup>15</sup> β 1 | style="text-align: right;" | {{#expr: 15 * ln(2) / ln(10) round 2}} | rowspan="2" | [[Universal Character Set|UCS-2]] characters, [[code unit]]s in the [[UTF-16]] [[character encoding]] | {{mono|int16_t}}, {{mono|short}},{{efn|name=notescb|garbage=16 short}} {{mono|int}}{{efn|name=notescb|garbage=16 int}} | {{mono|short}} | {{mono|Smallint}} | {{mono|short}} | {{mono|smallint}} | {{mono|INTEGER}}{{efn|name=fortran}} | {{mono|short}} | {{mono|i16}} |- | ''Unsigned:'' From 0 to 65,535, which equals 2<sup>16</sup> β 1 | style="text-align: right;" | {{#expr:16 * ln(2) / ln(10) round 2}} | {{mono|uint16_t, unsigned}},{{efn|name=notescb|garbage=16 int}} {{mono|unsigned int}}{{efn|name=notescb|garbage=16 int}} | {{mono|ushort}} | {{mono|Word}} | {{mono|char}}{{efn|name=notejavad}} | {{mono|unsigned smallint}} | {{n/a}} | {{mono|ushort}} | {{mono|u16}} |- | rowspan="2" style="text-align: right;" | 32 | rowspan="2" | word, [[Unsigned long integer|long]], doubleword, longword, int, i32, u32 | ''Signed:'' From [[2147483647 (number)|β2,147,483,648 to 2,147,483,647]], from β(2<sup>31</sup>) to 2<sup>31</sup> β 1 | style="text-align: right;" | {{#expr: 31 * ln(2) / ln(10) round 2}} | rowspan="2" | [[UTF-32]] characters, [[24-bit color|true color]] with alpha, [[FourCC]], pointers in [[32-bit computing]] | {{mono|int32_t}}, {{mono|int}},{{efn|name=notescb|garbage=32 int}} {{mono|long}}{{efn|name=notescb|garbage=32 long}} | {{mono|int}} | {{mono|LongInt}}; {{mono|Integer}}{{efn|name=notedelphic|garbage=signed}} | {{mono|int}} | {{mono|int}} | {{mono|INTEGER}}{{efn|name=fortran}} | {{mono|int}} | {{mono|i32}} |- | ''Unsigned:'' From 0 to 4,294,967,295, which equals 2<sup>32</sup> β 1 | style="text-align: right;" | {{#expr: 32 * ln(2) / ln(10) round 2}} | {{mono|uint32_t, unsigned}},{{efn|name=notescb|garbage=16 int}} {{mono|unsigned int}},{{efn|name=notescb|garbage=16 int}} {{mono|unsigned long}}{{efn|name=notescb|garbage=16 int}} | {{mono|uint}} | {{mono|LongWord}}; {{mono|DWord}}; {{mono|Cardinal}}{{efn|name=notedelphic|garbage=unsigned}} | {{n/a}} | {{mono|unsigned int}} | {{n/a}} | {{mono|uint}} | {{mono|u32}} |- | rowspan="2" style="text-align: right;" | 64 | rowspan="2" | word, doubleword, longword, long, long long, quad, quadword, qword, int64, i64, u64 | ''Signed:'' From {{tooltip|β(2<sup>63</sup>)|β9,223,372,036,854,775,808}} to {{tooltip|2<sup>63</sup> β 1|9,223,372,036,854,775,807}} | style="text-align: right;" | {{#expr: 63 * ln(2) / ln(10) round 2}} | rowspan="2" | Time (e.g. {{shy|milli|seconds}} since the [[Unix epoch]]), pointers in [[64-bit computing]] | {{mono|int64_t}}, {{mono|long}},{{efn|name=notescb|garbage=64 long}} {{mono|long long}}{{efn|name=notescb|garbage=64 long long}} | {{mono|long}} | {{mono|Int64}} | {{mono|long}} | {{mono|bigint}} | {{mono|INTEGER}}{{efn|name=fortran}} | {{mono|long}} | {{mono|i64}} |- | ''Unsigned:'' From 0 to {{tooltip|2<sup>64</sup> β 1|18,446,744,073,709,551,615}} | style="text-align: right;" | {{#expr: 64 * ln(2) / ln(10) round 2}} | {{mono|uint64_t}}, {{mono|unsigned long long}}{{efn|name=notescb|garbage=16 int}} | {{mono|ulong}} | {{mono|UInt64}}; {{mono|QWord}} | {{n/a}} | {{mono|unsigned bigint}} | {{n/a}} | {{mono|ulong}} | {{mono|u64}} |- | rowspan="2" style="text-align: right;" | 128 | rowspan="2"| octaword, double quadword, i128, u128 | ''Signed:'' From {{tooltip|β(2<sup>127</sup>)|β170,141,183,460,469,231,731,687,303,715,884,105,728}} to {{tooltip|2<sup>127</sup> β 1|170,141,183,460,469,231,731,687,303,715,884,105,727}} | style="text-align:right;" | {{#expr:127*ln2/ln10 round 2}} | rowspan="2" | Complex scientific {{shy|cal|cula|tions}}, [[IPv6]] addresses, [[GUID]]s | colspan="6" rowspan="2" style="text-align: center; background: #eaecf0;" | Only available as non-standard or compiler-specific extensions | {{mono|cent}}{{efn|name=notede|garbage=reserved}} | {{mono|i128}} |- | ''Unsigned:'' From 0 to {{tooltip|2<sup>128</sup> β 1|340,282,366,920,938,463,463,374,607,431,768,211,455}} | style="text-align: right;" | {{#expr:128*ln2/ln10 round 2}} | {{mono|ucent}}{{efn|name=notede|garbage=reserved}} | {{mono|u128}} |- | rowspan="2" style="text-align: right;" | ''n'' | rowspan="2" | ''n''-bit integer<br /> (general case) | ''Signed:'' β(2<sup>''n''β1</sup>) to (2<sup>''n''β1</sup> β 1) | colspan="2" | (''n'' β 1) log<sub>10</sub> 2 | C23: {{mono|_BitInt(n)}}, {{mono|signed _BitInt(n)}} | colspan="7" | [[Ada (programming language)|Ada]]: {{code|range -2**(n-1)..2**(n-1)-1|ada}} |- | ''Unsigned:'' 0 to (2<sup>''n''</sup> β 1) | colspan="2" | ''n'' log<sub>10</sub> 2 | C23: {{mono|unsigned _BitInt(n)}} | colspan="7" | Ada: {{code|range 0..2**n-1|ada}}, {{code|mod 2**n|ada}}; standard libraries' or third-party arbitrary arithmetic libraries' BigDecimal or Decimal classes in many languages such as Python, C++, etc. |} Different [[CPU]]s 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 (that can represent only the integers in a specified range). Some languages, such as [[Lisp (programming language)|Lisp]], [[Smalltalk]], [[REXX]], [[Haskell]], [[Python (programming language)|Python]], and [[Raku (programming language)|Raku]], support ''arbitrary precision'' integers (also known as ''infinite precision integers'' or ''[[bignum]]s''). Other languages that do not support this concept as a top-level construct may have libraries available to represent very large numbers using arrays of smaller variables, such as Java's {{mono|BigInteger}} class or [[Perl]]'s "{{mono|bigint}}" package.<ref>{{cite web |url=http://download.oracle.com/javase/6/docs/api/java/math/BigInteger.html |title=BigInteger (Java Platform SE 6) |publisher=Oracle |access-date=2011-09-11 }}</ref> These use as much of the computer's memory as is necessary to store the numbers; however, a computer has only a finite amount of storage, so they, too, can only represent a finite subset of the mathematical integers. These schemes support very large numbers; for example one kilobyte of memory could be used to store numbers up to 2466 decimal digits long. A [[Boolean data type|Boolean]] type is a type that can represent only two values: 0 and 1, usually identified with ''false'' and ''true'' respectively. <!-- Pascal has them the other way around --> 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. === Bytes and octets === {{Main article|Byte|Octet (computing)}} The term ''byte'' initially meant 'the smallest addressable unit of memory'. In the past, 5-, 6-, 7-, 8-, and 9-bit bytes have all been used. There have also been computers that could address individual bits ('bit-addressed machine'), or that could only address 16- or 32-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 used in the field of [[computer network]]ing, where computers with different byte widths might have to communicate. In modern usage ''byte'' almost invariably means eight bits, since all other sizes have fallen into disuse; thus ''byte'' has come to be synonymous with ''octet''. === Words === {{Main article|Word (computer architecture)}} The term 'word' is used for a small group of bits that are handled simultaneously by processors of a particular [[computer architecture|architecture]]. The size of a word is thus CPU-specific. Many different word sizes have been used, including 6-, 8-, 12-, 16-, 18-, 24-, 32-, 36-, 39-, 40-, 48-, 60-, and 64-bit. Since it is architectural, the size of a ''word'' is usually set by the first CPU in a family, rather than the characteristics of a later compatible CPU. The meanings of terms derived from ''word'', such as ''longword'', ''doubleword'', ''quadword'', and ''halfword'', also vary with the CPU and OS.<ref name="agnerfog" /> Practically all new desktop processors are capable of using 64-bit words, though [[Embedded system|embedded processors]] with 8- and 16-bit word size are still common. The [[36-bit word length]] was common in the early days of computers. One important cause of non-portability of software is the incorrect assumption that all computers have the same word size as the computer used by the programmer. For example, if a programmer using the C language incorrectly declares as {{mono|int}} a variable that will be used to store values greater than 2<sup>15</sup>β1, the program will fail on computers with 16-bit integers. That variable should have been declared as {{mono|long}}, which has at least 32 bits on any computer. Programmers may also incorrectly assume that a pointer can be converted to an integer without loss of information, which may work on (some) 32-bit computers, but fail on 64-bit computers with 64-bit pointers and 32-bit integers. This issue is resolved by C99 in [[stdint.h]] in the form of {{code|intptr_t}}. The ''bitness'' of a program may refer to the word size (or bitness) of the processor on which it runs, or it may refer to the width of a memory address or pointer, which can differ between execution modes or contexts. For example, 64-bit versions of [[Microsoft Windows]] support existing 32-bit binaries, and programs compiled for Linux's [[x32 ABI]] run in 64-bit mode yet use 32-bit memory addresses.<ref>{{cite news |author=Thorsten Leemhuis |date=2011-09-13 |title=Kernel Log: x32 ABI gets around 64-bit drawbacks |url=http://www.h-online.com/open/features/Kernel-Log-x32-ABI-gets-around-64-bit-drawbacks-1342061.html |archive-url=https://web.archive.org/web/20111028081253/http://www.h-online.com/open/features/Kernel-Log-x32-ABI-gets-around-64-bit-drawbacks-1342061.html |archive-date=28 October 2011 |access-date=2011-11-01 |publisher=www.h-online.com}}</ref> === Standard integer === The standard integer size is platform-dependent. In [[C (programming language)|C]], it is denoted by {{mono|int}} and required to be at least 16 bits. Windows and Unix systems have 32-bit {{mono|int}}s on both 32-bit and 64-bit architectures. === Short integer === A ''short integer'' can represent a whole number that may take less storage, while having a smaller range, compared with a standard integer on the same machine. In [[C (programming language)|C]], it is denoted by {{mono|short}}. It is required to be at least 16 bits, and is often smaller than a standard integer, but this is not required.<ref name="c99" /><ref name="drdobbsinteger" /> A conforming program can assume that it can safely store values between β(2<sup>15</sup>β1)<ref name="c-std-6.2.6.2p2">{{cite web |url=http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf |at=section 6.2.6.2, paragraph 2|title=ISO/IEC 9899:201x |access-date=2016-06-20 |publisher=open-std.org}}</ref> and 2<sup>15</sup>β1,<ref name="c-std-5.2.4.2.1">{{cite web |url=http://www.open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf |at=section 5.2.4.2.1|title=ISO/IEC 9899:201x |access-date=2016-06-20 |publisher=open-std.org}}</ref> but it may not assume that the range is not larger. In [[Java (programming language)|Java]], a {{mono|short}} is ''always'' a 16-bit integer. In the [[Windows API]], the datatype {{mono|SHORT}} is defined as a 16-bit signed integer on all machines.<ref name="agnerfog" /> {| class="wikitable" |+ Common short integer sizes |- ! [[Programming language]] ! Data type name ! [[Signedness]] ! Size in [[bytes]] ! Minimum value ! Maximum value |- | rowspan="2" | [[C (programming language)|C]] and [[C++]] | {{mono|short}} | signed | style="text-align: right;" | 2 | style="text-align: right;" | β32,767{{efn|The ISO C standard allows implementations to reserve the value with sign bit 1 and all other bits 0 (for signβmagnitude and two's complement representation) or with all bits 1 (for ones' complement) for use as a "trap" value, used to indicate (for example) an overflow.<ref name="c-std-6.2.6.2p2" />}} | style="text-align: right;" | +32,767 |- | {{mono|unsigned short}} | unsigned | style="text-align: right;" | 2 | style="text-align: right;" | 0 | style="text-align: right;" | 65,535 |- | rowspan="2" | [[C Sharp (programming language)|C#]] | {{mono|short}} | signed | style="text-align: right;" | 2 | style="text-align: right;" | β32,768 | style="text-align: right;" | +32,767 |- | {{mono|ushort}} | unsigned | style="text-align: right;" | 2 | style="text-align: right;" | 0 | style="text-align: right;" | 65,535 |- | [[Java (programming language)|Java]] | {{mono|short}} | signed | style="text-align: right;" | 2 | style="text-align: right;" | β32,768 | style="text-align: right;" | +32,767 |- | [[SQL]] | {{mono|smallint}} | signed | style="text-align: right;" | 2 <!-- (implementation-defined) --> | style="text-align: right;" | β32,768 | style="text-align: right;" | +32,767 |} === Long integer === A ''long integer'' can represent a whole [[integer]] whose [[range (computer science)|range]] is greater than or equal to that of a standard integer on the same machine. In [[C (programming language)|C]], it is denoted by {{mono|long}}. It is required to be at least 32 bits, and may or may not be larger than a standard integer. A conforming program can assume that it can safely store values between β(2<sup>31</sup>β1)<ref name="c-std-6.2.6.2p2" /> and 2<sup>31</sup>β1,<ref name="c-std-5.2.4.2.1" /> but it may not assume that the range is not larger. {{Table alignment}} {| class="wikitable col6center" |+ Common long integer sizes |- ! [[Programming language]] ! Approval Type ! [[Computing platform|Platform]]s ! Data type name ! Storage in [[bytes]] ! [[Signedness|Signed]] range ! [[Signedness|Unsigned]] range |- | [[C (programming)|C]] ISO/ANSI C99 | International Standard | [[Unix]], 16/32-bit systems<ref name="agnerfog" /><br />[[Windows]], 16/32/64-bit systems<ref name="agnerfog" /> | {{mono|long}} | 4<br />(minimum require{{shy}}ment 4) | {{val|β2147483647| to |+2147483647|fmt=commas}} | {{val|0|to|4294967295|fmt=commas}}<br />(minimum require{{shy}}ment) |- | [[C (programming)|C]] ISO/ANSI C99 | International Standard | [[Unix]],<br />64-bit systems<ref name="agnerfog" /><ref name="drdobbsinteger" /> | {{mono|long}} | 8<br />(minimum require{{shy}}ment 4) | {{val|β9223372036854775807|to|+9223372036854775807|fmt=commas}} | {{val|0|to|18446744073709551615|fmt=commas}} |- | [[C++]] ISO/ANSI | International Standard | [[Unix]], [[Windows]],<br />16/32-bit system | {{mono|long}} | 4 <ref>{{cite web |title=Fundamental types in C++|url=http://cppreference.com/wiki/language/types|publisher=cppreference.com|access-date=5 December 2010}}</ref><br />(minimum require{{shy}}ment 4) | {{val|β2147483648|to|+2147483647|fmt=commas}}<br /> | {{val|0|to|4294967295|fmt=commas}}<br />(minimum require{{shy}}ment) |- | [[C++/CLI]] | International Standard<br />[[ECMA-372]] | [[Unix]], [[Windows]],<br />16/32-bit systems | {{mono|long}} | 4 <ref>{{cite web| url=http://www.ecma-international.org/publications/files/ECMA-ST/ECMA-372.pdf |title=Chapter 8.6.2 on page 12|publisher=ecma-international.org}}</ref><br />(minimum require{{shy}}ment 4) | {{val|β2147483648|to|+2147483647|fmt=commas}}<br /> | {{val|0| to |4294967295|fmt=commas}}<br />(minimum require{{shy}}ment) |- | [[Visual Basic (classic)|VB]] | Company Standard | [[Windows]] | {{mono|Long}} | 4 <ref>VB 6.0 help file</ref> | {{val|β2147483648|to|+2147483647|fmt=commas}} | {{n/a}} |- | [[Visual Basic for Applications|VBA]] | Company Standard | [[Windows]], [[Mac OS X]] | {{mono|Long}} | 4<ref>{{cite web |url=http://msdn2.microsoft.com/en-us/library/aa164754(office.10).aspx |title=The Integer, Long, and Byte Data Types (VBA) |access-date=2006-12-19 |publisher=microsoft.com}}</ref> | {{val|β2147483648| to |+2147483647|fmt=commas}} | {{n/a}} |- | [[Microsoft SQL Server|SQL Server]] | Company Standard | [[Windows]] | {{mono|BigInt}} | 8 | {{val|β9223372036854775808|to|+9223372036854775807|fmt=commas}} | {{val|0|to|18446744073709551615|fmt=commas}} |- | [[C Sharp (programming language)|C#]]/ [[VB.NET]] | ECMA International Standard | [[Microsoft .NET]] | {{mono|long}} or {{mono|Int64}} | 8 | {{val|β9223372036854775808|to|+9223372036854775807|fmt=commas}} | {{val|0|to|18446744073709551615|fmt=commas}} |- | [[Java (programming language)|Java]] | International/Company Standard | [[Java platform]] | {{mono|long}} | 8 | {{val|β9223372036854775808|to|+9223372036854775807|fmt=commas}} | {{n/a}} |- | [[Pascal (programming language)|Pascal]] | ? | [[Windows]], [[UNIX]] | {{mono|int64}} | 8 | {{val|β9223372036854775808|to|+9223372036854775807|fmt=commas}} | {{val|0|to|18446744073709551615|fmt=commas}} (Qword type) |} === Long long === {{Redirect|long long||Long (disambiguation)}} In the [[C99]] version of the [[C programming language]] and the [[C++11]] version of [[C++]], a <CODE>long long</CODE> type is supported that has double the minimum capacity of the standard <CODE>long</CODE>. This type is not supported by compilers that require C code to be compliant with the previous C++ standard, C++03, because the {{mono|long long}} type did not exist in C++03. For an ANSI/ISO compliant compiler, the minimum requirements for the specified ranges, that is, β(2<sup>63</sup>−1)<ref name="c-std-6.2.6.2p2" /> to 2<sup>63</sup>β1 for signed and 0 to 2<sup>64</sup>β1 for unsigned,<ref name="c-std-5.2.4.2.1" /> must be fulfilled; however, extending this range is permitted.<ref>{{cite web| url=http://www.ericgiguere.com/articles/ansi-c-summary.html|title=The ANSI Standard: A Summary for the C Programmer|first=Eric|last=Giguere|date=December 18, 1987|access-date=2010-09-04}}</ref><ref>{{cite web|url=http://flash-gordon.me.uk/ansi.c.txt|title=American National Standard Programming Language C specifies the syntax and semantics of programs written in the C programming language.|access-date=2010-09-04|url-status=dead|archive-url=https://web.archive.org/web/20100822072551/http://flash-gordon.me.uk/ansi.c.txt|archive-date=2010-08-22}}</ref> This can be an issue when exchanging code and data between platforms, or doing direct hardware access. Thus, there are several sets of headers providing platform independent exact width types. The C [[standard library]] provides ''[[stdint.h]]''; this was introduced in C99 and C++11. == Syntax == {{main|Integer literal}} [[Integer literal]]s can be written as regular [[Arabic numerals]], consisting of a sequence of digits and with negation indicated by a [[hyphen-minus|minus sign]] before the value. However, most programming languages disallow use of commas or spaces for [[digit grouping]]. Examples of integer literals are: * <code>42</code> * <code>10000</code> * <code>-233000</code> <!-- do not use the real minus sign, as that isn't part of a literal --> There are several alternate methods for writing integer literals in many programming languages: * Many programming languages, especially those influenced by [[C (programming language)|C]], prefix an integer literal with <code>0X</code> or <code>0x</code> to represent a [[hexadecimal]] value, e.g. <code>0xDEADBEEF</code>. Other languages may use a different notation, e.g. some [[assembly language]]s append an <code>H</code> or <code>h</code> to the end of a hexadecimal value. * [[Perl]], [[Ruby (programming language)|Ruby]], [[Java (programming language)|Java]], [[Julia (programming language)|Julia]], [[D (programming language)|D]], [[Go (programming language)|Go]], [[C Sharp (programming language)|C#]], [[Rust (programming language)|Rust]], [[Python (programming language)|Python]] (starting from version 3.6), and [[PHP]] (from version 7.4.0 onwards<ref>https://www.php.net/manual/en/language.types.integer.php</ref>) allow embedded [[underscore]]s for clarity, e.g. <code>10_000_000</code>, and fixed-form [[Fortran]] ignores embedded spaces in integer literals. C (starting from [[C23 (C standard revision)|C23]]) and C++ use single quotes for this purpose. * In [[C (programming language)|C]] and [[C++]], a leading zero indicates an [[octal]] value, e.g. <code>0755</code>. This was primarily intended to be used with [[Modes (Unix)|Unix modes]]; however, it has been criticized because normal integers may also lead with zero.<ref>ECMAScript 6th Edition draft: https://people.mozilla.org/~jorendorff/es6-draft.html#sec-literals-numeric-literals {{webarchive|url=https://web.archive.org/web/20131216202526/https://people.mozilla.org/~jorendorff/es6-draft.html |date=2013-12-16 }}</ref> As such, [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[Haskell]], and [[OCaml]] prefix octal values with <code>0O</code> or <code>0o</code>, following the layout used by hexadecimal values. * Several languages, including [[Java (programming language)|Java]], [[C Sharp (programming language)|C#]], [[Scala (programming language)|Scala]], [[Python (programming language)|Python]], [[Ruby (programming language)|Ruby]], [[OCaml]], C (starting from C23) and C++ can represent binary values by prefixing a number with <code>0B</code> or <code>0b</code>. == Extreme values == In many programming languages, there exist predefined constants representing the least and the greatest values representable with a given integer type. Names for these include * [[SmallBASIC]]: {{code|MAXINT|lang=basic}}<ref>{{cite web|title=SmallBASIC {{!}} MAXINT|url=https://smallbasic.github.io/reference/1736|access-date=2025-01-20}}</ref> * [[Java (programming language)|Java]]: {{java|java.lang.Integer.MAX_VALUE}}, {{java|java.lang.Integer.MIN_VALUE}}<ref>{{cite web|title=Integer (Java Platform SE 8 )|url=https://docs.oracle.com/javase/8/docs/api///java/lang/Integer.html|access-date=2025-01-20}}</ref> *: Corresponding fields exist for the other integer classes in Java. * [[C (programming language)|C]]: {{c-lang|INT_MAX}}, etc.{{cn|date=January 2025}} ** [[GLib]]: {{c-lang|G_MININT}}, {{c-lang|G_MAXINT}}, {{c-lang|G_MAXUINT}}, ...<ref>{{cite web|title=Limits of Basic Types|url=https://web.mit.edu/barnowl/share/gtk-doc/html/glib/glib-Limits-of-Basic-Types.html|access-date=2025-01-20}}</ref> * [[Haskell (programming language)|Haskell]]: {{code|minBound}}, {{code|maxBound}}<ref>{{cite web|title=Prelude|url=https://hackage.haskell.org/package/base-4.21.0.0/docs/Prelude.html#t:Bounded}}</ref> * [[Pascal (programming language)|Pascal]]: {{code|MaxInt|pascal}}{{cn|date=January 2025}} * [[Python 2]]: {{python|sys.maxint}}{{cn|date=January 2025}} * [[Turing (programming language)|Turing]]: {{code|maxint}}<ref>{{cite book|author-last=Grogono|author-first=Peter|title=Programming with Turing and Object Oriented Turing|lccn=95010802|doi=10.1007/978-1-4612-4238-3|year=1995|publisher=Springer|location=New York|page=363}}</ref> == See also == * [[Arbitrary-precision arithmetic]] * [[Binary-coded decimal]] (BCD) * [[C data types]] * [[Integer overflow]] * [[Signed number representations]] == Notes == {{Notelist|notes= {{efn |name=notejavad | Java does not directly support arithmetic on {{mono|char}} types. The results must be cast back into {{mono|char}} from an {{mono|int}}.}} {{efn |name=notede | Reserved for future use. Not implemented yet. }} {{efn |name=notedelphic | The sizes of Delphi's {{mono|Integer}} and {{mono|Cardinal}} are not guaranteed, varying from platform to platform; usually defined as {{mono|LongInt}} and {{mono|LongWord}} respectively.}} {{efn |name=notescb | The sizes of {{mono|char}}, {{mono|short}}, {{mono|int}}, {{mono|long}} and {{mono|long long}} in C/C++ are dependent upon the implementation of the language.}} }} == References == {{Reflist|30em|refs= <ref name=drdobbsinteger>{{cite web |url=http://www.drdobbs.com/184401323 |title=The New C: Integers in C99, Part 1 |date=2000-12-01 |access-date=2010-09-04 |last=Meyers |first=Randy |publisher=drdobbs.com }}</ref> <ref name=c99>{{cite web| url=http://www.ericgiguere.com/articles/ansi-c-summary.html|title=The ANSI Standard: A Summary for the C Programmer |first=Eric |last=Giguere |date=1987-12-18 |access-date=2010-09-04}}</ref> <ref name=agnerfog>{{cite web|url=http://www.agner.org/optimize/calling_conventions.pdf |title=Calling conventions for different C++ compilers and operating systems: Chapter 3, Data Representation |date=2010-02-16 |access-date=2010-08-30 |last=Fog |first=Agner}}</ref> }} {{Data types}} {{DEFAULTSORT:Integer (Computer Science)}} [[Category:Data types]] [[Category:Computer arithmetic]] [[Category:Primitive types]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:C-lang
(
edit
)
Template:Cite book
(
edit
)
Template:Cite news
(
edit
)
Template:Cite web
(
edit
)
Template:Cn
(
edit
)
Template:Code
(
edit
)
Template:Data types
(
edit
)
Template:Efn
(
edit
)
Template:Java
(
edit
)
Template:Main
(
edit
)
Template:Main article
(
edit
)
Template:Mono
(
edit
)
Template:N/a
(
edit
)
Template:Notelist
(
edit
)
Template:Nowrap
(
edit
)
Template:Python
(
edit
)
Template:Redirect
(
edit
)
Template:Reflist
(
edit
)
Template:Section link
(
edit
)
Template:Short description
(
edit
)
Template:Shy
(
edit
)
Template:Table alignment
(
edit
)
Template:Tooltip
(
edit
)
Template:Val
(
edit
)
Template:Webarchive
(
edit
)