title: converting IP to byte/convert back to string
body: <p>I'm storing an IPV4 address on a SQLSERVER 2008 database as Binary(4). So, I'm converting the values before data input (and due to company restrictions I CANNOT create functions inside the db, well thats not up for discussion).</p>
  
  <pre><code>public static byte[] IpToBin(string ip)
  {
      return IPAddress.Parse(ip).GetAddressBytes();
  }
  
  public static string HexToIp(string ip)
  {
      return new IPAddress(long.Parse(ip, NumberStyles.HexNumber)).ToString(); 
  }
  </code></pre>
  
  <p>After IpToBin is called, the data generated is (for example 0x59FC09F3). When I call HexToIp the ip came reversed probably due little/big endian conversion. </p>
  
  <p>Could anyone please come up with a decent solution without 50 billion lines of code?</p>