BCC异或效验

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_16855077/article/details/84336936
/**
	 * 获取BCC校验码
	 * @param data
	 * @param start 开始位置0
	 * @param end  字节数组长度
	 * @return
	 */
	public static String getBCC(byte[] data, int start, int end) {
		String ret = "";
		byte BCC[] = new byte[1];
		for (int i = start; i < data.length; i++) {
			if (i == end) {
				break;
			}
			BCC[0] = (byte) (BCC[0] ^ data[i]);
		}
		String hex = Integer.toHexString(BCC[0] & 0xFF);
		if (hex.length() == 1) {
			hex = '0' + hex;
		}
		ret += hex.toUpperCase();
		return ret;
	}

猜你喜欢

转载自blog.csdn.net/qq_16855077/article/details/84336936
今日推荐