Short integer

From Wikipedia, the free encyclopedia

In several programming languages, short integer is a common datatype for those variables that can hold a positive or negative whole number whose range is less or equal to that of a standard integer on the same machine.

Although there are no general rules, the size of a short integer is usually either the same or a half of the size of a standard integer on the same system. Normally, a short integer variable will consist of 16 bits.

A variable defined as a short integer in one programming language may be different in size to a similarly defined variable in another. In some languages this size is fixed across platforms, while in others it is machine dependent. In some languages this datatype does not exist at all.

[edit] Signedness

In some programming languages, a short integer can be declared signed or unsigned. In signed shorts, one bit is typically used as a sign bit that indicates the sign of the number, dividing the number of positive numbers that the type can represent by two. This representation is called two's complement.

[edit] Common sizes

Programming language Platforms Data type name Signedness Storage in bytes Minimum range Maximum range
C and C++ all platforms short signed 2 -32,768
or -215
32,767
or 215-1
unsigned short unsigned 2 0 65,535
or 216-1
C# all platforms short signed 2 -32,768
or -215
32,767
or 215-1
ushort unsigned 2 0 65,535
or 216-1
Java all platforms short signed 2 -32,768
or -215
32,767
or 215-1

In the Windows API, the datatype SHORT is defined as a 16-bit signed integer on all machines.

[edit] See also