0

我得到这个字符串 8802000030000000C602000033000000000000800000008000000000000000001800000000000

这就是我期望从字符串转换的内容,

  88020000 long in little endian => 648 
  30000000 long in little endian => 48 
  C6020000 long in little endian => 710
 33000000 long in little endian => 51

左侧是我从字符串中获得的值,右侧是我期望的值。右侧的值可能是错误的,但是有什么办法可以从左侧获得右侧的值吗?

我在这里经历了几个线程

如何将 int 转换为 little endian 字节数组?

C# Big-endian ulong 来自 4 个字节

我尝试了完全不同的功能,但没有什么能给我带来与我期望的差不多或接近的价值。

更新:我正在阅读如下文本文件。大多数数据都是文本格式的,但突然间我得到了一堆图形信息,我不知道如何处理它。

    RECORD=28 

cVisible=1
dwUser=0
nUID=23
c_status=1
c_data_validated=255
c_harmonic=0
c_dlg_verified=0
c_lock_sizing=0
l_last_dlg_updated=0
s_comment=
s_hlinks=
dwColor=33554432
memUsr0=
memUsr1=
memUsr2=
memUsr3=
swg_bUser=0
swg_dConnKVA=L0
swg_dDemdKVA=L0
swg_dCodeKVA=L0
swg_dDsgnKVA=L0
swg_dConnFLA=L0
swg_dDemdFLA=L0
swg_dCodeFLA=L0
swg_dDsgnFLA=L0
swg_dDiversity=L4607182418800017408
cStandard=0
guidDB={901CB951-AC37-49AD-8ED6-3753E3B86757}
l_user_selc_rating=0
r_user_selc_SCkA=
a_conn1=21
a_conn2=11
a_conn3=7
l_ct_ratio_1=x44960000
l_ct_ratio_2=x40a00000
l_set_ct_ratio_1=
l_set_ct_ratio_2=

c_ct_conn=0

   ENDREC
 GRAPHICS0=8802000030000000C602000033000000000000800000008000000000000000001800000000000
 EOF
4

2 回答 2

2

你真的是字面意思那是一个字符串吗?它看起来是这样的:你有一堆 32 位的字,每个字用 8 个十六进制数字表示。每一个都以小端顺序呈现,低字节在前。您需要将其中的每一个解释为整数。因此,例如,88020000 是 88 02 00 00,即 0x00000288。

如果您能准确地阐明您所拥有的是什么——一个字符串、某种数字类型的数组,或者什么——那么进一步向您提供建议会更容易。

于 2012-07-10T22:18:01.810 回答
2

根据您想要解析输入字符串的方式,您可以执行以下操作:

string input = "8802000030000000C6020000330000000000008000000080000000000000000018000000";

for (int i = 0; i < input.Length ; i += 8)
{
    string subInput = input.Substring(i, 8);
    byte[] bytes = new byte[4];
    for (int j = 0; j < 4; ++j)
    {
        string toParse = subInput.Substring(j * 2, 2);
        bytes[j] = byte.Parse(toParse, NumberStyles.HexNumber);
    }

    uint num = BitConverter.ToUInt32(bytes, 0);
    Console.WriteLine(subInput + " --> " + num);
}

88020000 --> 648
30000000 --> 48
C6020000 --> 710
33000000 --> 51
00000080 --> 2147483648
00000080 --> 2147483648
00000000 --> 0
00000000 --> 0
18000000 --> 24
于 2012-07-10T22:30:03.280 回答