| | |
| | | for (int i = 0; i < 4; i++) { |
| | | bs[from + i] = Integer.valueOf(value & 0xff).byteValue();// 将最低位保存在低字节 |
| | | value = value >> 8; // 向右移8位 |
| | | if(value == 0){ |
| | | break ; |
| | | } |
| | | if(value == 0){ |
| | | break ; |
| | | } |
| | | } |
| | | } else { |
| | | throw new Exception("int2Bytes时数组越界"); |
| | |
| | | } |
| | | |
| | | /** |
| | | * 小端模式《数据低位在数组低字节》 |
| | | * 整形转成BCD编码,字节顺序是倒的 |
| | | * @param i |
| | | * @param bs |
| | | * @param from |
| | | * @return 返回 |
| | | */ |
| | | public static void int2BCD_LE(int i, byte[] bs, int from)throws Exception { |
| | | String str = "" + i; |
| | | byte[] b = null; |
| | | if (str.length() % 2 == 0) { |
| | | b = new byte[str.length() / 2]; |
| | | } else { |
| | | b = new byte[(str.length() / 2) + 1]; |
| | | } |
| | | encodeBCD_LE(str, b, 0, b.length); |
| | | |
| | | int len = bs.length ; |
| | | int bLen = b.length ; |
| | | for(int j = 0; (j < len && j < bLen); j++){ |
| | | bs[from + j] = b[j] ; |
| | | } |
| | | } |
| | | |
| | | /** |
| | | * 大端模式《数据低位在数组高字节》 |
| | | * 长整形转成BCD编码 |
| | | * @param l |