【发布时间】:2018-09-28 22:17:33
【问题描述】:
我正在尝试编写一个控制台应用程序,它将数据作为输入并将其分成两个
示例:如果我将值 0x00000000A0DB383E 作为输入传递,我的输出应如下所示:
var LowerValue = 0x00000000A0DB0000 (last 2 bytes 383E (index 14-17) replaced with 0000)
var UpperValue = 0x000000000000383E (middle 2 bytes A0DB (index 10-13) replaced with 0000)
到目前为止,我已经在下面尝试过,但不知道如何进一步进行。任何帮助将不胜感激
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.IO;
namespace SplitFunction
{
class Program
{
static void Main(string[] args)
{
byte[] rawValue = BitConverter.GetBytes(0x00000000A0DB383E);
SplitData(rawValue);
Console.ReadKey();
}
public static byte[] SplitDta(byte[] input)
{
byte[] lowerValues = new byte[8];
Array.Copy(input, 0, lowerValues, 4, 4);
foreach(var lowerValue in lowerValues)
Console.WriteLine(lowerValue);
return lowerValues;
}
}
}
【问题讨论】:
-
你的输入是字节数组吗?
-
嗨@paulF是的
-
您确实意识到该值仅包含 4 个字节,对吧?只需检查
rawValue数组即可。 -
您的代码显示您正在传递一个长值并转换为一个数组 - 这就是您想要的吗?或者你想以长值结束。请注意,GetBytes 可能会首先为您提供一个低字节数组,而不是最后一个。
-
@juharr 好吧,他在顶部 2 + 2 个字节说,然后他使用 8 个字节..