title: SQL: Binary to IP Address
body: <p>I'm trying to convert A binary IP to a human-readable IP</p>
  
  <pre><code>SELECT HEX( `ip_bin` ) FROM `log_metadata`
  </code></pre>
  
  <p>gives me
      <code>4333D26E000000000000000000000000</code></p>
  
  <p>And </p>
  
  <pre><code>SELECT INET_NTOA(0x4333D26E)
  </code></pre>
  
  <p>gives me <code>67.51.210.110</code></p>
  
  <p>So I tried: </p>
  
  <pre><code>SELECT
    SUBSTRING( CONVERT(HEX(`ip_bin`), CHAR(32)), 1, 8 ) AS `A`
  , INET_NTOA( 
    SUBSTRING( CONVERT(HEX(`ip_bin`), CHAR(32)), 1, 8 ) 
                                                       ) AS `B`
  , INET_NTOA(hex(`ip_bin`))  AS `C`
  , INET_NTOA(`ip_bin`)       AS `D`
  FROM `log_metadata`
  </code></pre>
  
  <p>But I only get</p>
  
  <pre><code>+----------+------------+------------+---------+
  | A        | B          | C          | D       |
  +----------+------------+------------+---------+
  | 4333D26E | 0.0.16.237 | 0.0.16.237 | 0.0.0.0 |
  +----------+------------+------------+---------+
  </code></pre>
  
  <p>Any suggestions?</p>