title: SHA1 encoding to hex has 40 characters and 160 bits
body: <p>An SHA1 digest should be 160 bits long. Still it is normally represented as a  string with 40 characters. Considering 8-bits-bytes and that 1 char corresponds to 1 byte, it seems to me the SHA1 digest should have 20 bytes and it's hex representation 40 bytes.</p>
  
  <p>For example, using OpenSSL I could get the following results (after manually removing extra information added):</p>
  
  <p><em>PLAIN MESSAGE: The only possible revolution is inside us</em></p>
  
  <pre><code>openssl dgst -sha1 -hex dgsttxt &amp;&gt; sha1_hex
  
  32 64 66 61 33 35 66 62 35 37 34 65 36 62 65 36 32 33 62 37 63 36 31 61 63 61 32 63 61 31 65 66 39 30 36 62 39 63 38 34
  
  openssl dgst -sha1 -binary dgsttxt &amp;&gt; sha1_binary
  2D FA 35 FB 57 4E 6B E6 23 B7 C6 1A CA 2C A1 EF 90 6B 9C 84
  </code></pre>
  
  <p>Applying a wc in each file I get</p>
  
  <pre><code>wc sha1_binary sha1_hex 
   0  1 20 sha1_binary
   0  1 40 sha1_hex
   0  2 60 total
  </code></pre>
  
  <p>So I have two questions:</p>
  
  <ol>
  <li>Why are there 20 more characters in the hex dump?</li>
  <li>How are those extra bits inserted? I could note each byte in the hex dump starts with either <strong>3</strong> or <strong>6</strong>. Is there a particular reason for that?</li>
  </ol>
  
  <p>I have already seen a similar question <a href="https://stackoverflow.com/questions/3704010/why-is-a-sha-1-hash-40-characters-long-if-it-is-only-160-bit">here</a> but I am not sure if I am too stupid to understand the answers or if they are really poor. Any help is appreciated.</p>