我有一个存储在字节数组中的ipv4地址。在索引n
和索引n+3
之前,每个索引需要4个字节。
(index) n n+1 n+2 n+3
[..] [..] [..] [ 1st byte ][ 2nd ] [ 3rd ] [ 4th ] [..] [..]
如何将此构造复制到字符串。我想收到像“192.168.0.1”这样的字符串,而
byteArray[n] = 192;
byteArray[n+1] = 168;
byteArray[n+2] = 0;
byteArray[n+3] = 1;
最后,问题解决了,解决方法是:
string str = recCommand.parameters[10] + "." + recCommand.parameters[11] +
"." + recCommand.parameters[12] + "." + recCommand.parameters[13];
答案 0 :(得分:3)
像这样的东西
byte[] some = { 192, 168, 0, 1 };
String ip = "" + some[0] + "." + some[1] + "." + some[2] + "." + some[3];
Console.WriteLine("ip=" + ip );