| | |
| | | throw new Exception("byte2Int时数组越界"); |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 小端模式《数据低位在数组低字节》 |
| | | * 与方法bytes2Int算法一样,只是把顺序反过来 |
| | | * @param bs 字节数组 |
| | | * @param from 字节数组起始位置 |
| | | * @param has3Byte 是否包含数据下标为3的字节,如果不包含实际处理的是3字节的整数 |
| | | * @return |
| | | */ |
| | | public static long bytes2Int_LE(byte[] bs, int from, boolean has3Byte) throws Exception { |
| | | boolean b = isOutOfArrLength(bs.length, (from - 1) + 4); |
| | | if (!b) { |
| | | long s = 0; |
| | | long s0 = bs[from + 0] & 0xFF ;// 数据的最低位在低字节 |
| | | long s1 = bs[from + 1] & 0xFF ; |
| | | long s2 = bs[from + 2] & 0xFF ; |
| | | long s3 = 0L ; |
| | | if(!has3Byte){ |
| | | s3 = bs[from + 3] & 0xFF ; |
| | | } |
| | | |
| | | |
| | | // S0不变 |
| | | s1 <<= 8; |
| | | s2 <<= 16; |
| | | s3 <<= 24; |
| | | s = s0 | s1 | s2 | s3; |
| | | if(s < 0){ |
| | | //s = Integer.MAX_VALUE -s ; |
| | | s = Integer.MAX_VALUE * 2 + 1 + s + 1 ; |
| | | } |
| | | return s; |
| | | } else { |
| | | throw new Exception("byte2Int时数组越界"); |
| | | } |
| | | } |
| | | /** |
| | | * 大端模式《数据低位在数组高字节》 |
| | | * 无符号short类型转换成2位byte数组 |