title: Updating an Array of Checkboxes based on a hidden field (and vice versa) with the binary representation
body: <p>I have on my form a group of checkboxes that belong together. The number of checkboxes is fixed, let's say 8. There is also a hidden Input field. When the page loads, I want the checkboxes to update so that they show the binary representation of the hidden value (should be unsigned integer).</p>
  <p>E.g. on load the value of the hidden field is 123, therefor the field of checkboxes look like this:</p>
  <blockquote>
  <p>[ ][X][X][X][X][ ][X][X]</p>
  </blockquote>
  <p>If a checkbox then is altered the hidden value should be updated.</p>
  <p>E.g. after the last checkbox is clicked (and thereby turned off):</p>
  <blockquote>
  <p>[ ][X][X][X][X][ ][X][ ]</p>
  </blockquote>
  <p>-&gt; Hidden value: 122</p>
  <pre><code>&lt;input name=&quot;test[0]&quot; type=&quot;checkbox&quot; value=&quot;1&quot;&gt;
  &lt;input name=&quot;test[1]&quot; type=&quot;checkbox&quot; value=&quot;1&quot;&gt;
  &lt;input name=&quot;test[2]&quot; type=&quot;checkbox&quot; value=&quot;1&quot;&gt;
  &lt;input name=&quot;test[3]&quot; type=&quot;checkbox&quot; value=&quot;1&quot;&gt;
  &lt;input name=&quot;test[4]&quot; type=&quot;checkbox&quot; value=&quot;1&quot;&gt;
  &lt;input name=&quot;test[5]&quot; type=&quot;checkbox&quot; value=&quot;1&quot;&gt;
  &lt;input name=&quot;test[6]&quot; type=&quot;checkbox&quot; value=&quot;1&quot;&gt;
  &lt;input name=&quot;test[7]&quot; type=&quot;checkbox&quot; value=&quot;1&quot;&gt;
  &lt;input id=&quot;realValue&quot; type=&quot;hidden&quot; value=&quot;123&quot;&gt;
  </code></pre>
  <p>The Idea is, that I can then simply save a whole set of (very similar) binary options in just one int field in my database, without creating a bazillion boolean fields.</p>
  <p>I guess there is a JS library that can do exactly that, but I couldn't find something.. Does someone have a simple solution?</p>