如何从十六进制转换 GPS 经度和纬度 [英] How to convert GPS Longitude and latitude from hex

查看:29
本文介绍了如何从十六进制转换 GPS 经度和纬度的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从 GPS 跟踪设备转换 GPS 数据.该公司提供了协议手册,但不清楚.我能够从我从设备收到的数据包中解码的大部分数据.通信是通过 TCP/IP 进行的.我在解码经度和纬度的十六进制值时遇到问题.这是手册中的一个示例:

I am trying to convert GPS data from GPS tracking device. The company provided protocol manual, but it's not clear. Most of the data I was able to decoding from the packets I received from the device. The communication is over TCP/IP. I am having a problem decoding the hex value of the longitude and latitude. Here is an example from the manual:

例子:22º32.7658'=(22X60+32.7658)X3000=40582974,然后转成十六进制数40582974(十进制)= 26B3F3E(十六进制)最后是0x02 0x6B 0x3F 0x3E.

Example: 22º32.7658’=(22X60+32.7658)X3000=40582974, then converted into a hexadecimal number 40582974(Decimal)= 26B3F3E(Hexadecimal) at last the value is 0x02 0x6B 0x3F 0x3E.

我想知道如何从十六进制反转为经度和纬度.设备将发送 26B3F3E.我想知道得到22º32.7658的过程.

I would like to know how to reverse from the hexadecimal to longitude and latitude. The device will send 26B3F3E. I want to know the process of getting 22º32.7658.

此协议适用于 GT06 和 Heacent 908.

This protocol applies to GT06 and Heacent 908.

推荐答案

  1. 将所有四个值存储在无符号 32 位变量中.
    v1 = 0x02, v2 = 0x6b, v3 = 0x3f, v4 = 0x3e.

计算 (v4 <<48) |(v3 <<32) |(v2 <<16) |v1 这将产生一个保存十进制值 40582974 的变量.

Compute (v4 << 48) | (v3 << 32) | (v2 << 16) | v1 this will yield a variable holding the value 40582974 decimal.

将其转换为浮点数并除以 30,000.0(您的 3,000 是错误的),得到 1,352.765

Convert this to a float and divide it by 30,000.0 (your 3,000 was an error), this will give you 1,352.765

切成整数并除以 60.这将得到 22.

Chop to integer and divide by 60. This will give you the 22.

将第 4 步得到的数字乘以 60,然后从第 3 步得到的数字中减去.这将得到 1352.765 - 22*60 或 32.765.

Multiply the number you got in step 4 by 60 and subtract it from the number you got in step 3. This will give you 1352.765 - 22*60 or 32.765.

这是你的答案2232.765.

这篇关于如何从十六进制转换 GPS 经度和纬度的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆