十六进制字符串到INT32-Little Endian(DCBA格式)Javascript [英] Hex String to INT32 - Little Endian (DCBA Format) Javascript

查看:56
本文介绍了十六进制字符串到INT32-Little Endian(DCBA格式)Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

根据可悲的文档实施某些操作,而没有任何信息.

Implementing something based on a pathetic documentation without no info nothing.

示例就是这样

(7F02AAF7)H => (F7AA027F)H = -139853185

说,即使我将 7F02AAF7 转换为 F7AA027F ,那么通过'parseInt('F7AA027F',16)'与我期望的不同.

Let's say even if I convert 7F02AAF7 to F7AA027F, then still the output via 'parseInt('F7AA027F', 16)' is different from what I am expecting.

我做了一些Google搜索,发现了该网站 http://www.scadacore.com/field-tools/programming-calculators/online-hex-converter/

I did some google search and found this website http://www.scadacore.com/field-tools/programming-calculators/online-hex-converter/

在这里,当您输入 7F02AAF7 时,它将在 INT32-Little Endian(DCBA)系统下被处理为所需编号.我尝试了这个搜索字词,但没有运气.您能告诉我我到底应该在这里做什么,是否有任何node.js库可以帮助我解决这个问题.

Here when you input 7F02AAF7 then it is processed to wanted number under INT32 - Little Endian (DCBA) system. I tried this search term but no luck. Can you please tell me what exactly am I supposed to do here and is there any node.js library which can help me with this.

推荐答案

您可以采用 的出色答案href ="https://stackoverflow.com/users/157247/tj-crowder"> TJCrowder 并使用 给定字节的DataView#setUint8 DataView#getInt32 和littleEndian的指示器.

You could adapt the excellent answer of T.J. Crowder and use DataView#setUint8 for the given bytes with DataView#getInt32 and an indicator for littleEndian.

var data = '7F02AAF7'.match(/../g);

// Create a buffer
var buf = new ArrayBuffer(4);
// Create a data view of it
var view = new DataView(buf);

// set bytes
data.forEach(function (b, i) {
    view.setUint8(i, parseInt(b, 16));
});

// get an int32 with little endian
var num = view.getInt32(0, 1);
console.log(num);

这篇关于十六进制字符串到INT32-Little Endian(DCBA格式)Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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