如何将Byte数组转换为Long [英] How to convert Byte array to 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:
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屋!