title: Converting a hexadecimal number to binary in ruby
body: <p>I am trying to convert a hex value to a binary value (each bit in the hex string should have an equivalent four bit binary value). I was advised to use this:</p>
  
  <pre><code>num = "0ff" # (say for eg.)
  bin = "%0#{num.size*4}b" % num.hex.to_i
  </code></pre>
  
  <p>This gives me the correct output <code>000011111111</code>. I am confused with how this works, especially <code>%0#{num.size*4}b</code>. Could someone help me with this?</p>