当前位置:网站首页>对占用多字节和位的报文信号解析详解
对占用多字节和位的报文信号解析详解
2022-06-30 06:57:00 【程序员草帽】
在实际应用报文解析程序当中需要对占20位的一个报文信号进行数据解析,由于好久没有对报文解析这里的程序进行编写了所以还算了一番,现将计算过程进行记录以供大家参考,后续解析时遇到占多字节的报文信号时可以一用。
接收到的报文信号(20位,占用两个半字节):
1010 10110011 10111011
如上所示: 红色为第一个字节,低八位;蓝色为第二个字节,中八位;绿色为第三个字节,高4位。
1010 10110011 10111011 转为十进制为 701371
10110011 10111011 转为十进制为 46011
10111011 转为十进制为 187
(10110011(转为十进制为179)) * 256 = 45824
46011 - 187 = 45824 即可得出中八位为二进制位乘256(2的八次方)算出;
验证后同理可得 高四位为二进制位乘以256*256(2的十六次方)算出;
若是20位数最低的4位是填充的第一个字节的高四位,则通过右移4位将其放在最低4位,最后再通过 &0x0F 算出结果
解析过程为最低四位直接转十进制,中八位转十进制后乘以16(即为2的4次方),高八位转十进制后乘以16*256(即为2的12次方),相加之后得最后的十进制结果。
当然,如果位数小的话,能想到的还有更多方式,通过移位、位或、与或进行巧妙处理,还有通过函数对报文二进制数据串进行截取后直接转为十进制数,换一种思路也不失为一种好的方法。
边栏推荐
- MySQL优化:从十几秒优化到三百毫秒
- Essence of signal slot macros signal and slot
- 编写并运行第一个Go语言程序
- RT thread Kernel Implementation (IV): multi priority
- Redis cache
- If I am in Zhuhai, where can I open an account? In addition, is it safe to open a mobile account?
- 【Hot100】11. Container with the most water
- Ftplib+ tqdm upload and download progress bar
- Keil - the "trace HW not present" appears during download debugging
- Finished product upgrade procedure
猜你喜欢

MySQL优化:从十几秒优化到三百毫秒

0 basic job transfer software test, how to achieve a monthly salary of 9.5k+

How does the CPU recognize the code?

随机网络,无标度网络,小世界网络以及NS小世界的性能对比matlab仿真
![[fuzzy neural network] mobile robot path planning based on Fuzzy Neural Network](/img/39/c9bf235828b6d50e7931876fa4a918.png)
[fuzzy neural network] mobile robot path planning based on Fuzzy Neural Network
![[transfer] analysis of memory structure, cache and DMA architecture](/img/c1/6a872babf9b5236d226de455a49b8b.png)
[transfer] analysis of memory structure, cache and DMA architecture

Rising posture series: fancy debugging information
![[my advanced OpenGL learning journey] about the access methods of vector and matrix classification of OpenGL shaders: xyzw/rgba/stpq and array subscripts](/img/ed/76db436ab5e35fba742dc287402fe3.png)
[my advanced OpenGL learning journey] about the access methods of vector and matrix classification of OpenGL shaders: xyzw/rgba/stpq and array subscripts

Installation du serveur linux redis

Google Earth engine (GEE) - Murray global tidal wetland change V1 (1999-2019) data set
随机推荐
[fuzzy neural network] mobile robot path planning based on Fuzzy Neural Network
Four tips in numpy
SOC项目AHB_SD_HOST控制器设计
如果我在珠海,到哪里开户比较好?另外,手机开户安全么?
Linux服务器安装Redis
Base64 encoding method implemented by native JS
[Hot100]10. Regular Expression Matching
No module named 'pyqt5 QtMultimedia‘
元宇宙由哪些底层技术支撑?
Four great happenings on earth
【最全】linux服务器上安装Mysql
Egret P2 physical engine (1) small ball falling demo
Qstring to const char*
0 basic job transfer software test, how to achieve a monthly salary of 9.5k+
memcpy内存重叠的解决
史上最全一句话木马
【json-tutorial】第一章学习笔记
How to convert XML to JSON
Servlet principle
Which securities company is good for opening a mobile account? Also, is it safe to open an account online?