C#字节[]长时间反向不起作用 [英] C# Byte[] to long reverse not working

查看:149
本文介绍了C#字节[]长时间反向不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么该程序不起作用?我将字节数组转换为long.然后从长远来看,我转换回一个字节数组.结果字节数组与原始字节数组不同.

Why is this program not working? I convert a byte array to long. Then from the long I convert back to a byte array. The resulting byte array is not the same as original.

class Program
{
    static void Main(string[] args)
    {
        byte[] myBytes = { 0, 0, 0, 32, 56, 99, 87, 34, 56, 56, 34, 33, 67
                         , 56, 66, 72, 1, 0, 0, 56, 0, 22};

        long data = BitConverter.ToInt64(myBytes, 0);

        byte[] byteData = BitConverter.GetBytes(data);

        Console.WriteLine("byte array: " + BitConverter.ToString(myBytes));
        Console.WriteLine("byte array: " + BitConverter.ToString(byteData));
    }
}

推荐答案

字节长度超过long可以容纳的字节数(8个字节,64位).

The length of bytes exceed a long can hold(8 bytes, 64 bits).

对于其他解决方案,我建议使用 BigInteger 您的目标框架高于(包括).Net 4.0.

For alternative solution, I'd suggest to use BigInteger if your target framework is higher than(including) .Net 4.0.

这篇关于C#字节[]长时间反向不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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