package com.yyy.test; import java.util.zip.CRC32; public class TestJava { public static void main(String arg[]) { System.out.println("time:"+System.currentTimeMillis() ); String str = "100000"; byte a = (byte) 0xff; // 扩充的长度 int len = str.length(); int maxLen = (len - 1) / 4 * 4 + 4; // 增加的个数 int add = maxLen - len; byte tempAdd[]=new byte[add]; for (int i = 0; i < tempAdd.length; i++) { tempAdd[i]=a; } byte[] xxx=byteMerger(str.getBytes(), tempAdd); CRC32 c = new CRC32(); c.update(xxx); System.out.println(Integer.toHexString((int) c.getValue())); System.out.println("time:"+System.currentTimeMillis() ); byte[] temp = new byte[8]; temp[0]=0x31; temp[1]=0x30; temp[2]=0x30; temp[3]=0x30; temp[4]=0x30; temp[5]=0x30; temp[6]=(byte) 0xff; temp[7]=(byte) 0xff; System.out.println(new String(temp)); CRC32 c1 = new CRC32(); c1.update(temp); System.out.println(Integer.toHexString((int) c1.getValue())); } //java 合并两个byte数组 public static byte[] byteMerger(byte[] byte_1, byte[] byte_2){ byte[] byte_3 = new byte[byte_1.length+byte_2.length]; System.arraycopy(byte_1, 0, byte_3, 0, byte_1.length); System.arraycopy(byte_2, 0, byte_3, byte_1.length, byte_2.length); return byte_3; } }
java byte追加_byte数组追加 java
最新推荐文章于 2022-03-02 09:55:16 发布