Integer Types

An integer type represents a subset of the whole numbers. The generic integer types are Integer and Cardinal; use these whenever possible, since they result in the best performance for the underlying CPU and operating system. The table below gives their ranges and storage formats for the Delphi compiler.

Generic integer types

Type Range Format .NET Type Mapping

Integer -2147483648..2147483647signed 32-bit Int32 Cardinal0..4294967295 unsigned 32-bitUInt32

Fundamental integer types include Shortint, Smallint, Longint, Int64, Byte, Word, and Longword. Fundamental integer types

Type Range Format .NET Type Mapping

Shortint -128..127 signed 8-bit SByte

Smallint -32768..32767 signed 16-bit Int16

Longint -2147483648..2147483647signed 32-bit Int32 Int64 -2A63..2A631 signed 64-bit Int64

Byte 0..255 unsigned 8-bit Byte

Word 0..65535 unsigned 16-bitUInt16

Longword0..4294967295 unsigned 32-bitUInt32

In general, arithmetic operations on integers return a value of type Integer, which is equivalent to the 32-bit Longint. Operations return a value of type Int64 only when performed on one or more Int64 operand. Hence the following code produces incorrect results.

To get an Int64 return value in this situation, cast I as Int64:

For more information, see Arithmetic operators.

Note: Some standard routines that take integer arguments truncate Int64 values to 32 bits. However, the High, Low, Succ, Pred, Inc, Dec, IntToStr, and IntToHex routines fully support Int64 arguments. Also, the Round, Trunc, strToInt64, and strToInt64Def functions return Int64 values. A few routines cannot take Int64 values at all.

When you increment the last value or decrement the first value of an integer type, the result wraps around the beginning or end of the range. For example, the Shortint type has the range 128..127; hence, after execution of the code var I: Shortint;

the value of I is 128. If compiler range-checking is enabled, however, this code generates a runtime error.

Project Management Made Easy

Project Management Made Easy

What you need to know about… Project Management Made Easy! Project management consists of more than just a large building project and can encompass small projects as well. No matter what the size of your project, you need to have some sort of project management. How you manage your project has everything to do with its outcome.

Get My Free Ebook

Post a comment