1200字范文,内容丰富有趣,写作的好帮手!
1200字范文 > java实现对无符号整数的支持

java实现对无符号整数的支持

时间:2019-02-08 06:05:02

相关推荐

java实现对无符号整数的支持

package cn.miw.hp.test;public class ToUnsigned {public static long getUnSignedLong(long l) {return getLong(longToDword(l), 0);}// 将long型数据转换为Dword的字节数组(C/C++的无符号整数)private static byte[] longToDword(long value) {byte[] data = new byte[4];for (int i = 0; i < data.length; i++) {data[i] = (byte) (value >> (8 * i));}return data;}// 将C/C++的无符号 DWORD类型转换为java的long型private static long getLong(byte buf[], int index) {int firstByte = (0x000000FF & ((int) buf[index]));int secondByte = (0x000000FF & ((int) buf[index + 1]));int thirdByte = (0x000000FF & ((int) buf[index + 2]));int fourthByte = (0x000000FF & ((int) buf[index + 3]));long unsignedLong = ((long) (firstByte | secondByte << 8 | thirdByte << 16 | fourthByte << 24)) & 0xFFFFFFFFL;return unsignedLong;}}

本内容不代表本网观点和政治立场,如有侵犯你的权益请联系我们处理。
网友评论
网友评论仅供其表达个人看法,并不表明网站立场。