经度读数以度为1x10 ^ -7度的lsb,带符号2的补码 [英] longitude reading measured in degrees with a 1x10^-7 degree lsb, signed 2’s complement

查看:239
本文介绍了经度读数以度为1x10 ^ -7度的lsb,带符号2的补码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过udp数据包从GPS单元接收数据。 Lat / Lng值以十六进制表示。



示例数据

13BF71A8 =纬度(33.1313576)

BA18A506 =经度( - 文件解释经度/纬度的读数是用1x10 ^ -7度的lsb(带符号2的补码)度数度量。



对于我可以使用此公式转换的纬度:

13BF71A8 = 331313576 * 0.0000001 = 33.1313576


此代码适用于Lat而不是Lng:

pre $函数convertLat(h){
var latdec = parseInt(h,16);
var lat = latdec * 0.0000001;
返回拉特;
}

console.log(LAT:+ convertLat(13BF71A8));

我无法转换经度值。有谁知道如何转换经度?

解决方案

因为您使用带符号的数字,您需要指定一个点,十六进制代码应该翻转到底部。这将发生在 7FFFFFFF 以上。现在更新你的代码来检查输入是否大于这个数字,如果是这样,从输入中减去它。

 函数convert(h){
dec = parseInt(h,16);
return(dec dec * 0.0000001:
0 - ((parseInt('FFFFFFFF',16) - dec)* 0.0000001);

$ / code>

您的示例工作的唯一原因是因为输出预期为正值。




由于 AlexWien 在评论中提到:由于解析 7FFFFFFF FFFFFFFF 每次都会给出相同的整数,您可以将它们存储为常量。它们的值分别为 2147483647 4294967295


I am receiving data from a gps unit via a udp packet. Lat/Lng values are in hex.

Example Data
13BF71A8 = Latitude (33.1313576)
BA18A506 = Longitude (-117.2790010)

The documentation explains that longitude/latitude readings are measured in degrees with a 1x10^-7 degree lsb, signed 2’s complement.

For the Latitude I can convert using this formula:
13BF71A8 = 331313576 * 0.0000001 = 33.1313576

This code works for Lat but not for Lng:

function convertLat(h){
var latdec = parseInt(h,16);
    var lat = latdec * 0.0000001;
    return lat;
}

console.log("LAT: " + convertLat("13BF71A8"));

I am having trouble converting the Longitude value. Does anyone know how to convert the Longitude?

解决方案

Because you are using signed numbers, you need to specify a point at which the hexadecimal code should flip to the bottom. This will be happening at 7FFFFFFF and up. Now update your code to check if the input is greater than this number, and if so, subtract it from the input.

function convert(h) {
    dec = parseInt(h, 16);
    return (dec < parseInt('7FFFFFFF', 16)) ?
        dec * 0.0000001 :
        0 - ((parseInt('FFFFFFFF', 16) - dec) * 0.0000001);
}

The only reason your example worked is because the output was expected to be positive.


As AlexWien mentioned in the comments: Since parsing 7FFFFFFF and FFFFFFFF are giving the same integers every time, you could store them as constants. Their values are 2147483647 and 4294967295 respectively.

这篇关于经度读数以度为1x10 ^ -7度的lsb,带符号2的补码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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