To contents Next section

4.1.1 int

Int is short for integer, or integer number. They are normally 32 bit integers, which means that they are in the range -2147483648 to 2147483647. Note that on some machines an int might be larger than 32 bits. Since they are integers, no decimals are allowed. An integer constant can be written in several ways:
78 // decimal number
0116 // octal number
0x4e // hexadecimal number
'N' // Ascii character
All of the above represent the number 78. Octal notation means that each digit is worth 8 times as much as the one after. Hexadecimal notation means that each digit is worth 16 times as much as the one after. Hexadecimal notation uses the letters a, b, c, d, e and f to represent the numbers 10, 11, 12, 13, 14 and 15. The ASCII notation gives the ASCII value of the character between the single quotes. In this case the character is N which just happens to be 78 in ASCII.

Integers are coded in 2-complement and overflows are silently ignored by Pike. This means that if your integers are 32-bit and you add 1 to the number 2147483647 you get the number -2147483648. This works exactly as in C or C++.

All the arithmetic, bitwise and comparison operators can be used on integers. Also note these functions:

int intp(mixed x)
This function returns 1 if x is an int, 0 otherwise.
int random(int x)
This function returns a random number greater or equal to zero and smaller than x.
int reverse(int x)
This function reverses the order of the bits in x and returns the new number. It is not very useful.
int sqrt(int x)
This computes the square root of x. The value is always rounded down.

To contents Next section