博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
java CRC8
阅读量:7107 次
发布时间:2019-06-28

本文共 892 字,大约阅读时间需要 2 分钟。

public class Crc8 {

private int crc = 0;public void update(final byte[] input, final int offset, final int len) {    for (int i = 0; i < len; i++) {        update(input[offset + i]);    }}public void update(final byte[] input) {    update(input, 0, input.length);}private final void update(final byte b) {    crc ^= b;    for (int j=0;j<8;j++){        if ((crc & 0x01) != 0)            crc = (crc >> 1) ^ 0x8c;        else            crc = crc >> 1;    }}public void update(final int b) {    update((byte) b);}public int getValue() {    return (crc & 0xFF);}public void reset() {    crc = 0;}

// /**

// * Test
// */
// public static void main(String[] args) {
// CRC8 crc = new CRC8();
// crc.reset();
// crc.update("test".getBytes());
// System.out.println("181=" + crc.getValue());
// crc.reset();
// crc.update("hello world".getBytes());
// System.out.println("59=" + crc.getValue());
// }

转载地址:http://uqvhl.baihongyu.com/

你可能感兴趣的文章
关于解构
查看>>
P4389 付公主的背包
查看>>
AspNetCore 使用log4net+IExceptionFilter 记录错误日志
查看>>
MyEclipse更改项目名web发布名字不改问题
查看>>
Html5 js FileReader接口
查看>>
Swift 扩展
查看>>
Spring Data JPA 介绍
查看>>
Bootstrap 的栅格
查看>>
java I/O框架 (二)文件操作(File)
查看>>
python中的argparse模块学习
查看>>
POJ - 1753 Flip Game(状压枚举)
查看>>
Execute to Parse %: 29.76,数据库硬解析过高,监控告警提示数据库硬解析比例过低...
查看>>
三、Hadoop命令
查看>>
moment.js笔记
查看>>
2.1 Word 插入 smartart、图表
查看>>
css+div的存在问题
查看>>
PoEdu - C++阶段班【Po学校】- Lesson03-4_构造函数&赋值函数&拷贝构造函数&学习方式 - 第6天...
查看>>
通过url给action传中文参数乱码解决方案
查看>>
糊涂窗口综合症
查看>>
Hadoop的调度器总结(转)
查看>>