java byte追加_byte数组追加 java

本文展示了如何在Java中合并两个字节数组(byteMerger方法),以及使用CRC32进行数据校验。示例中通过创建额外的字节数组填充到原始字符串的字节数组后,然后进行合并,最后计算CRC32校验值。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

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;       }   }

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值