PHP二进制操作初体验

点击上面的链接,看看原理和相关代码


[number_to_buffer]:准备分析数字10597059
[number_to_buffer]:    余数:195
[number_to_buffer]:    整商:10597059
[number_to_buffer]:准备分析数字41394
[number_to_buffer]:    余数:178
[number_to_buffer]:    整商:41394
[number_to_buffer]:数字161小于256 计算:161

通过数字转HEX字符串: 0xA1B2C3
[get_ck_sum]:转换成HEX字符串:0x019DF2
[buffer_ck_sum]:第1次计算求值
[buffer_ck_sum]:    计算前:0, 0x00
[buffer_ck_sum]:    计算后:1, 0x01
[buffer_ck_sum]:    求余后:1, 0x01
[buffer_ck_sum]:第2次计算求值
[buffer_ck_sum]:    计算前:1, 0x01
[buffer_ck_sum]:    计算后:158, 0x9E
[buffer_ck_sum]:    求余后:158, 0x9E
[buffer_ck_sum]:第3次计算求值
[buffer_ck_sum]:    计算前:158, 0x9E
[buffer_ck_sum]:    计算后:400, 0x0190
[buffer_ck_sum]:    求余后:144, 0x90
[buffer_ck_sum]:最终结果:111, 0x6F

传入数字方式 最终结算结果: 0x6F

Buffer方式 array(240,134,141,186,53,61,16,3,0,108,103,246,53,61,16,3,0,108,103,246,53,61,16,3,0,108,103,246,53,61,16,3,0,108,97,70) 最终结算结果: 0xC0

Buffer判断是否通过校验 array(240,134,141,186,53,61,16,3,0,108,103,246,53,61,16,3,0,108,103,246,53,61,16,3,0,108,103,246,53,61,16,3,0,108,97,70,192) : 通过

HEX字符串方式 BDBDBDBDA314CEAAC2464D8D3C 最终计算结果: 0xBE

HEX字符串 判断是否通过校验 BDBDBDBDA314CEAAC2464D8D3CC1: 未通过