BCC异或效验

/**
	 * 获取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;
	}

如果你热衷技术,喜欢交流,欢迎加入我们!

BCC异或效验_第1张图片

你可能感兴趣的:(通信常用算法)