【发布时间】:2014-01-02 21:19:33
【问题描述】:
我尝试将 IP 地址转换为长值:
byte[] Ip = new byte[4] { 192, 168, 1, 0 };
UInt32 Ret1 = (((UInt32)Ip[0]) << 24) |
(((UInt32)Ip[1]) << 16) |
(((UInt32)Ip[2]) << 8) |
(((UInt32)Ip[3]));
UInt32 Ret2 = BitConverter.ToUInt32(Ip, 0);
Ret1 返回3232235776(正确值)
Ret2 返回108736 (?)
为什么会有这种差异?
【问题讨论】:
-
Ret1 returns 3232235776 (the correct value)?根据哪个字节序?使用更多相关的API怎么样new IPAddress(new byte[] { 192, 168, 1, 0 })
标签: c# bitconverter