title: Ruby: How can I write a digest to a file in binary format
body: <p>I need to store a Digest::SHA512 object to a file in <strong>binary</strong> format.<br>
  That seemed trivial, but whatever I try just write it as an hexadecimal string.<br>
  I was expecting the following code to work:</p>
  
  <pre><code>bindigest=digest.update(chall)
  File.open('sha1.bin', 'wb') {|file| file.write(bindigest) }
  </code></pre>
  
  <p>but it does not: it convert to plain text.<br>
  A similar question seems unanswered:
  <a href="https://stackoverflow.com/questions/9883649/can-i-serialize-a-ruby-digestsha1-instance-object">Can I serialize a ruby Digest::SHA1 instance object?</a></p>
  
  <p>Using unpack tools require translating a bigint into a binary string, which again is not trivial...
  Any suggestion?</p>
  
  <p>Thank you in advance!</p>