Integer datatype

From REALbasicWiki

(Redirected from Int16)
Jump to: navigation, search
Overall article skill Skill ranges from beginner (green) to expert (red)

The term integer is the computer representation of an integer in the mathematical sense. It is defined by its length in bytes (or bits) and the fact that it is considered as always positive (i.e. unsigned) or positive/negative (i.e. signed).

For example, a 1-byte (i.e. 8-bit) integer can take 256 different values.

  1. If it is unsigned, and considering that zero is a value, it can represent integer values in the range 0–255
  2. If it is signed, zero is the value in the middle, so such an integer can represent values in the range –127 to +128

NOTE: in REALbasic, integer is also a synonym for Int32

Contents

[edit] Notation

Integers types are usually noted the following way:

  1. The letter U for an unsigned integer or the letter S (or nothing) for a signed integer
  2. Int
  3. The length in bits (8, 16, 32, 64)

[edit] Integer types in REALbasic

Type Name Value range Comment
Unsigned UInt8 0 to 255
UInt16 0 to 65535
UInt32 0 to 4,294,967,295
UInt64 0 to 18,446,744,073,709,551,615
Signed Int8 –128 to +127
Int16 –32768 to +32767 It is the same as the older Short datatype.1
Int32 –2,147,483,648 to +2,147,483,647 Integer is a synonym for Int32
Int64 –9,223,372,036,854,775,808 to +9,223,372,036,854,775,807

[edit] Calculations with integers: a warning

Be aware that calculations on integers will never raise error, but it does not mean that the result is correct. Consider the following code

dim a as Int8

a = 25
a = a * 2000

//... result a = 80 !!!

You should get 50,000 as a result but the variable a was defined as a single-byte integer (Int8) which cannot hold such a large number. You then get a wrong result, but no RuntimeException is raised.

[edit] References and notes

1. Originally, Short was allowed only in external function declarations, but recent changes to the compiler removed this restriction.

Personal tools
related