转换字节数组INT24 [英] Converting Byte Array To Int24

查看:167
本文介绍了转换字节数组INT24的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读与BinaryReader的文件。

I am reading a file with BinaryReader.

有我想在地址0x37E拉的数据,但它是INT24。因此,即使我读了3个字节,我不能将它转换为INT24。

There are data I want to pull at the address 0x37E but it is int24. So even I read 3 bytes, I can't convert it to int24.

你有什么建议吗?

我使用C#和我的工作有关STFS包东西。

I'm using C# and am working on STFS package stuff.

推荐答案

为了改造一个字节数组到INT24 ,你需要知道数据的字节序。这意味着:该信息,如果 11 22 33 的解释是: 0x112233 0x332211

In order to transform a byte array to an int24, you need to know the endianness of the data. This means: the information if 11 22 33 is supposed to mean 0x112233 or 0x332211.

根据该字节顺序,可以将数据转换,如

Depending on this endianness, you can convert the data such as

int24 result_bigendian = array[0] * 65536 + array[1] * 256 + array[2] // (1)

int24 result_littleendian = array[2] * 65536 + array[1] * 256 + array[0] // (2)

(RESP。

int24 result_littleendian = array[0] + array[1] * 256 + array[2] * 65536 // (3)

如果您更喜欢;注意区别:(1))

if you prefer that; note the difference to (1))

我不知道C#;有可能是要达到的目标更简单的方法。

I don't know about C#; there may be an easier way to reach the goal.

这篇关于转换字节数组INT24的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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