1
0
mirror of https://github.com/lidgren/lidgren-network-gen3.git synced 2026-05-16 15:16:33 +09:00

ToHexString optimized

This commit is contained in:
lidgren
2010-08-08 07:38:45 +00:00
parent 7f49001c11
commit a5ab4ab485
2 changed files with 11 additions and 5 deletions

View File

@@ -143,14 +143,18 @@ namespace Lidgren.Network
public static string ToHexString(byte[] data)
{
StringBuilder sb = new StringBuilder(data.Length * 2);
foreach (byte b in data)
char[] c = new char[data.Length * 2];
byte b;
for (int i = 0; i < data.Length; ++i)
{
sb.AppendFormat("{0:X2}", b);
b = ((byte)(data[i] >> 4));
c[i * 2] = (char)(b > 9 ? b + 0x37 : b + 0x30);
b = ((byte)(data[i] & 0xF));
c[i * 2 + 1] = (char)(b > 9 ? b + 0x37 : b + 0x30);
}
return sb.ToString();
return new string(c);
}
/// <summary>
/// Gets my local IP address (not necessarily external) and subnet mask
/// </summary>

View File

@@ -19,6 +19,8 @@ namespace UnitTests
throw new NetException("setting enabled message types failed");
Console.WriteLine("Misc tests OK");
Console.WriteLine("Hex test: " + NetUtility.ToHexString(new byte[]{0xDE,0xAD,0xBE,0xEF}));
}
}
}