如何将Byte数组转换为Long [英] How to convert Byte array to Long

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

问题描述

如何将Byte数组转换为Long?



这里我有一个字节数组



How to convert Byte array to Long?

Here I have i array of the byte

bytDataReceived(0)=76
bytDataReceived(1)=116
bytDataReceived(2)=157
bytDataReceived(3)=77





现在 bytDataReceived 数组必须转换为长



转换后的长值应为 1282710861



可以任意1帮助我



Now bytDataReceived array have to convert to long

after convert the long value should be 1282710861

can any1 help me

推荐答案





使用BitConverter.ToInt64方法 [ ^ ]







它不起作用,因为你'你的数组中有4个字节,要转换为long,你需要8个字节。

所以,使用 BitConverter.ToInt32方法 [ ^ ]将这些字节转换为Int32,然后转换为Int64。

但重要的是:

Hi,

Use the BitConverter.ToInt64 Method[^]



It doesn''t work because you''ve 4 bytes in your array, and to convert to a long, you need 8 bytes.
So, use the BitConverter.ToInt32 Method[^] to convert these bytes to an Int32, and then cast to an Int64.
But important:
AnnuBhai写道:
AnnuBhai wrote:

bytDataReceived(0)= 76


bytDataReceived(1)= 116


bytDataReceived(2)= 157


bytDataReceived(3)= 77


bytDataReceived(0)=76

bytDataReceived(1)=116

bytDataReceived(2)=157

bytDataReceived(3)=77




如果将该字节数组转换为整数,则不会得到1282710861.

这是1282710861的正确字节数组:


If you convert that byte array to an integer, you don''t will get 1282710861.
This is the correct byte array for 1282710861:

bytDataReceived(0)=76
bytDataReceived(1)=157
bytDataReceived(2)=116
bytDataReceived(3)=77



希望这有帮助。


Hope this helps.


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

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