整数是短整型或整型数字.它们是正常的32为整型,范围是-2147483648 到 2147483647.(注意在一些机子上,整数可能会超过32位.) pike编译的时候用的是没有32位限制的大整数雷,因此,整数可以是任意的长度.既然是整数,就不允许有小数的出现.一个整数常量可以有几种写法:
形式 例子 介绍
-?[1-9][0-9]* 78 十进制数
-?0[0-7]* 0116 八进制数
-?0[xX][0-9a-fA-F]+ 0x4e 十六进制数
-?0[bB][01]+ 0b1001110 二进制数
-?'\\?.' 'N' 字符的ASCII
上面所有的描述都是数字78.每个八进制符号中的每个阿拉伯数字是见8进1,十六进制数每个符号中的阿拉伯数字是见16进1.十六进制数用字母a,b,c,d,e,f分表代表数字10,11,12,13,14,15.二进制数中的每个阿拉伯数字是见2进1,只用到数字1,0.ASCII中两个单引号之间的字母代表值.按这种方法,在ASCII表中,N正好代表78.一些特殊字符,比如换行符不能用单个的符号代替.[quote]The special generation sequence for those characters, listed under strings, must be used instead. Specifically this applies to the single quote character itself, which has to be written as '\''.[/quote]
整数可以用所有的算术,位,比较运算.另外需要注意一些方法:
int intp(mixed x)
判断x是否为整数,是返回1,否则返回0
int random(int x)
随机得到一个大于等于0,小于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)
得到x的平发根,值一般是四舍五入的.
形式 例子 介绍
-?[1-9][0-9]* 78 十进制数
-?0[0-7]* 0116 八进制数
-?0[xX][0-9a-fA-F]+ 0x4e 十六进制数
-?0[bB][01]+ 0b1001110 二进制数
-?'\\?.' 'N' 字符的ASCII
上面所有的描述都是数字78.每个八进制符号中的每个阿拉伯数字是见8进1,十六进制数每个符号中的阿拉伯数字是见16进1.十六进制数用字母a,b,c,d,e,f分表代表数字10,11,12,13,14,15.二进制数中的每个阿拉伯数字是见2进1,只用到数字1,0.ASCII中两个单引号之间的字母代表值.按这种方法,在ASCII表中,N正好代表78.一些特殊字符,比如换行符不能用单个的符号代替.[quote]The special generation sequence for those characters, listed under strings, must be used instead. Specifically this applies to the single quote character itself, which has to be written as '\''.[/quote]
整数可以用所有的算术,位,比较运算.另外需要注意一些方法:
int intp(mixed x)
判断x是否为整数,是返回1,否则返回0
int random(int x)
随机得到一个大于等于0,小于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)
得到x的平发根,值一般是四舍五入的.