当前位置:网站首页>对占用多字节和位的报文信号解析详解
对占用多字节和位的报文信号解析详解
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次方),相加之后得最后的十进制结果。
当然,如果位数小的话,能想到的还有更多方式,通过移位、位或、与或进行巧妙处理,还有通过函数对报文二进制数据串进行截取后直接转为十进制数,换一种思路也不失为一种好的方法。
边栏推荐
- Connection Flood攻击原理
- ROS-URDF
- Browser downloads files as attachments
- 2、 Layout system
- 安装setup对应的组件
- How to set the hot deployment of idea web project
- Finished product upgrade procedure
- 编写并运行第一个Go语言程序
- [hot100] palindrome substring and longest palindrome substring
- [daily question] 535 Encryption and decryption of tinyurl
猜你喜欢

QT generate random number qrandomgenerator

leetcode:98. 验证二叉搜索树

Go常用命令
![[docsify basic use]](/img/9d/db689f5f13708f3e241474afeca1d0.png)
[docsify basic use]

SOC_SD_CLK

RT thread migration to s5p4418 (IV): thread synchronization

史上最全一句话木马

Xshell传输文件

RT thread Kernel Implementation (II): critical area, object container

0 basic job transfer software test, how to achieve a monthly salary of 9.5k+
随机推荐
经纬恒润再次荣获PACCAR集团 10PPM 质量奖
[docsify basic use]
Four great happenings on earth
Idea shortcut key
[semidrive source code analysis] [x9 chip startup process] 34 - RTOS side display module SDM_ display_ Init display initialization source code analysis
[my advanced OpenGL learning journey] about the access methods of vector and matrix classification of OpenGL shaders: xyzw/rgba/stpq and array subscripts
Porting RT thread to s5p4418 (II): dynamic memory management
Mysql5.7 compressed version installation tutorial
oracle
leetcode:98. Validate binary search tree
安装setup对应的组件
ROS program compilation, like no compilation, refers to the execution of the old compiled executable program
Qstring to const char*
JS widget wave JS implementation of wave progress bar animation style
Fastapi learning Day2
ROS-URDF
SQL Server2005中SUM函数内嵌套IF语句
RT thread migration to s5p4418 (I): scheduler
Rising posture series: fancy debugging information
【docsify基本使用】