- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试计算 ASCII 十六进制值数组的校验和。
假设我有以下内容
char exArray[] = "3030422320303030373830434441453141542355";
这是 20 对十六进制值,每个代表一个 ASCII 字符(例如 0x41 = A)。如何拆分它们以计算校验和?
或者,如何将数组中的两个值合并为一个值?(例如“4”、“1”->“41”)
最佳答案
@pmg:
First step would be converting the string representation (in hex) to an integer.
For the 2nd part, try ('4' - '0') * 16 + ('1' - '0')
这最终成功了,喜欢它的简单性,
我的实现现在看起来有点像这样。
uint8_t t = 0, tem, tem2, sum;
uint32_t chksum = 0;
void checkSum(void)
{
while (t < 40)
{
asciiToDec(exArray[t]);
tem = global.DezAscii[0];
t++;
asciiToDec(exArray[t]);
tem2 = global.DezAscii[0];
t++;
sum = (tem) * 16 + (tem2);
chksum += sum;
}
}
void asciiToDec(uint8_t value)
{
if (value == 'A')
global.DezAscii[0] = 10;
else if (value == 'B')
global.DezAscii[0] = 11;
else if (value == 'C')
global.DezAscii[0] = 12;
else if (value == 'D')
global.DezAscii[0] = 13;
else if (value == 'E')
global.DezAscii[0] = 14;
else if (value == 'F')
global.DezAscii[0] = 15;
else
global.DezAscii[0] = value;
}
关于C. ASCII 十六进制值数组的校验和计算,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52511728/
如何在 PHP 中生成 CRC-8 校验和? 最佳答案 function crcnifull ($dato, $byte) { static $PolyFull=0x8c; for ($i=0
我正在编写代码来使用 32 位无符号整数计算 CRC16。当尝试打印执行 CRC 操作的 XOR 函数的返回值时,它总是打印 0。我尝试了各种调试方法,例如打印语句,但是,我似乎无法弄清楚! 这是我的
ThinkPHP3.2.3验证码显示、刷新、校验 ,具体如下: 显示验证码 首先在Home/Controller下创建一个公共控制器PublicController
我想将自定义验证绑定(bind)到 TimePicker 自定义控件,但下面的代码显示“无法将内容添加到 TimePicker 的对象类型。”。
目录 Spring 校验(validator,JSR-303)实现 什么是JSR-303规范 与Spring MVC结合 实体类添加
导包和配置 导入 JSR 303 的包、hibernate valid 的包 ?
我是一名优秀的程序员,十分优秀!