Reputation: 41
I have a short code C# about how to convert long decimal to IP Address. But I am not sure about the base logic behind it. Could someone please explain the idea behind the following code:
IPAddress ip = new IPAddress(16885952);
Byte[] b = new Byte[4];
b = ip.GetAddressBytes();
Console.WriteLine("Address: "+b[0]+"." + b[1] + "." + b[2] + "." + b[3]);
Upvotes: 1
Views: 3087
Reputation: 11247
By hand, using int
calculation.
16885952 % 256 = 192
16885952 / 256 % 256 = 168
16885952 / 256 / 256 % 256 = 1
16885952 / 256 / 256 / 256 = 1
Upvotes: 4