title: Is there a difference between WKB and the hex value returned in PostGIS
body: <p>I've been doing some experimenting with PostGIS, and here's what I've noticed:</p>
  
  <p>Suppose I have a table defined as follows:</p>
  
  <pre><code>CREATE TABLE IF NOT EXISTS geomtest (
      id SERIAL PRIMARY KEY,
      name TEXT NOT NULL,
      geom geometry(POLYGON, 4326) NOT NULL
  );
  </code></pre>
  
  <p>And I add the following polygon:</p>
  
  <pre><code>SRID=4326;POLYGON((0 0,0 10,10 10,10 0,0 0))
  </code></pre>
  
  <p>If I query the <code>geom</code> column on its own, I get a Hex representation of the geometry. If I instead call <code>ST_AsBinary(geom)</code>, I get a binary representation.</p>
  
  <p>However, when I convert both the hex and binary representations to an array of bytes, the results I get are slightly different. The first comment is the result I get by converting the hex into binary, and the next is straight from <code>ST_AsBinary()</code></p>
  
  <pre><code>//[1 3 0 0 32 230 16 0 0 1 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
  //[1 3 0 0 0 1 0 0 0 5 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 36 64 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0]
  </code></pre>
  
  <p>As you can see, the first 4 bytes are identical; representing whether it's in big or little endian, and the type of geometry (3, in this case a Polygon). The rest of the bytes are the same too. The only difference is there are a few extra bytes added after the first 4.</p>
  
  <p>I wondered if this had to do with representing the projection (SRID=4326), but I haven't found any evidence to that.</p>
  
  <p>If someone could shed some light on this, I'd greatly appreciate it.</p>