title: How to 'convert' amount of Hz to appropriate byte/bit format?
body: <p>I am programming an IR camera. But the internal register for storing the refreshrate (bits 9, 8 and 7 of 16 in total) only accepts 1's and 0's of course. For example, a value of 0b110 means 32Hz and 0b111, 64Hz. How can I best convert a given integer (<code>refresh_rate</code>) value between 0.5Hz and 64Hz to 0b000 - 0b111 when looking at the Refresh rate control picture?</p>
  
  <p><img src="https://i.imgur.com/mu7ieVv.png" alt=""></p>
  
  <p>To be honest, I haven't tried anything yet because I think it requires a weird hack. However I have been thinking of a lookuptable, I think that is possible but requires more memory and it has to be memory efficient since it is programmed on an Arduino Due. </p>
  
  <p>Note: You can see that the refresh_rate is an <code>uint16_t</code> which does not accept floating point values such as 0.5Hz, however, I am probably not going to use the 0.5Hz setting.</p>
  
  <pre class="lang-cpp prettyprint-override"><code>// the end-user currently has to pass a value between 7 and 0
  void mlx90650::set_refresh_rate(uint16_t refresh_rate) {
      // So the refresh rate may not be higher than 7 (0b111) since this register only 
  accepts 3 bits. The memory map is:
  /*
      | decimal | bits  |  
      (decimal 0) 0 0 0 IR refresh rate = 0.5Hz 
      (decimal 1) 0 0 1 IR refresh rate = 1Hz 
      (decimal 2) 0 1 0 IR refresh rate = 2Hz (default) 
      (decimal 3) 0 1 1 IR refresh rate = 4Hz 
      (decimal 4) 1 0 0 IR refresh rate = 8Hz 
      (decimal 5) 1 0 1 IR refresh rate = 16Hz 
      (decimal 6) 1 1 0 IR refresh rate = 32Hz 
      (decimal 7) 1 1 1 IR refresh rate = 64H
  */
  }
  </code></pre>
  
  <p>I want that this function converts for example 64Hz to 0b111.</p>