读书人

WIFI IP变换

发布时间: 2012-09-25 09:55:59 作者: rapoo

WIFI IP转换
private String intToIp(int i) {
/**
* " -- 表示双引号(")
* & -- 表示位与运算符(&)
* < -- 表示小于运算符(<)
* > -- 表示大于运算符(>)
*   -- 表示空格( )
*/
return
( i & 0xFF) + "." +
((i >> 8 ) & 0xFF) + "." +
((i >> 16 ) & 0xFF) + "." +
((i >> 24 ) & 0xFF)
;
}

由于int是32位,和0xff相与后,高24比特就会被清0。

Integral Types and Values
The values of the integral types are integers in the following ranges:

* For byte, from -128 to 127, inclusive
* For short, from -32768 to 32767, inclusive
* For int, from -2147483648 to 2147483647, inclusive
* For long, from -9223372036854775808 to 9223372036854775807, inclusive
* For char, from '\u0000' to '\uffff' inclusive, that is, from 0 to 65535

读书人网 >移动开发

热点推荐