从十六进制解压缩Dec-通过位偏移量

问题描述 投票:0回答:1

我有一个十六进制数据块,其中包括传感器的设置,我将包括十六进制的开始代码段(LSB在前):


F501517C 8150D4DE 04010200 7001010105F32A04 F4467000 00000AFF 0502D402


这直接来自文档,将十六进制解码为dec:

3.1。完整的标识符和设置记录(0x7C)

Offset   Length (bytes)    Field description

0x00     6                 Full identifier
0x06     40                Settings

3.1.1完整标识符

Offset      Field description

0x00        Product Type
0x01        Device Type
0x02        Software Major Version
0x03        Software Minor Version
0x04        Hardware Major Version
0x05        Hardware Minor Version

3.1.2设置

Offset   Length(bit)   Offset(bit)  Default value   Min   Max     Field Description
0x00     8             0            0               0     255     Country number
0x01     8             0            0               0     255     District number
0x02     16            0            0               0     9999    Sensor number
...
0x27

这是我唯一需要解码的信息。偏移列必须是理解这一点的技巧。

  1. 十六进制值从哪里偏移?
  2. 我在第一个十六进制字符串中看到7C。
  3. “设置”部分的小数部分变为0x27 = 39,这在3.1部分中以40表示。
c bitmap hex decimal offset
1个回答
1
投票
Value in dump - separated in bytes - bytes in memory F501517C - F5 01 51 7C - 7C 51 01 F5 8150D4DE - 81 50 D4 DE - DE D4 50 81 04010200 - 04 01 02 00 - 00 02 01 04

现在让我们将它们分配给字段。下一个列表将两个记录串联在一起。

Byte Offset Field description 7C 0x00 Product Type 51 0x01 Device Type 01 0x02 Software Major Version F5 0x03 Software Minor Version DE 0x04 Hardware Major Version D4 0x05 Hardware Minor Version Byte Offset Length(bit) Offset(bit) Default value Min Max Field Description 50 0x00 8 0 0 0 255 Country number 81 0x01 8 0 0 0 255 District number 00,02 0x02 16 0 0 0 9999 Sensor number

结果是否有意义,是您的决定:

产品类型= 0x7C

设备类型= 0x51 = 81十进制(也可以是ASCII'Q')

软件专业版次要版本= 0x01.0xF5 = 1.245十进制

    硬件专业版次要版本= 0xDE.0xD4 = 222.212
  • 国家/地区= 0x50 =十进制80(也可以是ASCII'P')
  • 区号= 0x81 = 129十进制(也许0x01 = 1,设置了位7?)
  • 传感器编号= 0x0002 = 2个十进制(假定为大端)”>
© www.soinside.com 2019 - 2024. All rights reserved.