<html>
  <head>
    <meta content="text/html; charset=windows-1252"
      http-equiv="Content-Type">
  </head>
  <body bgcolor="#FFFFFF" text="#000000">
    In C++ I found the following code sample:<br>
    <table>
      <tbody>
        <tr>
          <td class="votecell">
            <div class="vote"> </div>
            <br>
          </td>
          <td class="answercell">
            <div class="post-text" itemprop="text">
              <p>Nobody mentioned the Standard C++ Library: <a
                  href="http://www.sgi.com/tech/stl/bitset.html"><code>std::bitset<N></code></a>.<br>
                Or the boost version: <a
href="http://www.boost.org/doc/libs/1_36_0/libs/dynamic_bitset/dynamic_bitset.html"><code>boost::dynamic_bitset</code></a>.</p>
              <p>No need to roll your own:</p>
              <pre style="" class="default prettyprint prettyprinted"><code><span class="com">#include</span><span class="pln"> </span><span class="str"><bitset></span><span class="pln">
</span><span class="com">#include</span><span class="pln"> </span><span class="str"><iostream></span><span class="pln">

</span><span class="kwd">int</span><span class="pln"> main</span><span class="pun">()</span><span class="pln">
</span><span class="pun">{</span><span class="pln">
    std</span><span class="pun">::</span><span class="pln">bitset</span><span class="pun"><</span><span class="lit">5</span><span class="pun">></span><span class="pln"> x</span><span class="pun">;</span><span class="pln">

    x</span><span class="pun">[</span><span class="lit">1</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">1</span><span class="pun">;</span><span class="pln">
    x</span><span class="pun">[</span><span class="lit">2</span><span class="pun">]</span><span class="pln"> </span><span class="pun">=</span><span class="pln"> </span><span class="lit">0</span><span class="pun">;</span><span class="pln">
    </span><span class="com">// Note x[0-4]  valid</span><span class="pln">

    std</span><span class="pun">::</span><span class="pln">cout </span><span class="pun"><<</span><span class="pln"> x </span><span class="pun"><<</span><span class="pln"> std</span><span class="pun">::</span><span class="pln">endl</span><span class="pun">;</span><span class="pln">
</span><span class="pun">}</span></code></pre>
            </div>
          </td>
        </tr>
      </tbody>
    </table>
     <br>
    and you could map them more or less as follows:<br>
    sex=m|f=0|1<br>
    mood=h|s=0|1<br>
    mature=a|c=0|1<br>
    color=r|b=0|1<br>
    handed=r|l=0|1<br>
    Thus, a female child who is happy, likes re and is right handed
    would encode to: 10100<br>
    <br>
    in PDP-11 assembler there's a BSB command (bit set byte), and you
    can embed assembler in C functions.<br>
    <br>
    Hope it helps<br>
    RickF<br>
    <br>
    <div class="moz-cite-prefix">On 11/17/2014 9:28 PM, James McDonald
      wrote:<br>
    </div>
    <blockquote cite="mid:546AD914.9080106@jamesmcdonald.id.au"
      type="cite">Hi All,
      <br>
      <br>
      I am wondering how to do the following:
      <br>
      <br>
      Say I have a list of values I want to assign to a person e.g.
      <br>
      <br>
      1. Male
      <br>
      2. Female
      <br>
      3. Happy
      <br>
      4. Sad
      <br>
      5. Child
      <br>
      6. Red is favorite color
      <br>
      7. Blue is favorite color
      <br>
      8. RIght handed
      <br>
      9. Left handed
      <br>
      etc.
      <br>
      <br>
      Now how do I make the list contain numerical values that I can
      then add together and then end up with a number that I can reverse
      and discern which values were assigned to the person?
      <br>
      <br>
      I believe that there is something in binary that means you can
      assign bit or a corresponding number to each option and then pull
      out the selections programmatically
      <br>
      <br>
      My problem is I can't figure out what to Google to teach myself
      how to do it.
      <br>
      <br>
      Can anyone point me in the right direction?
      <br>
      <br>
      Thanks.
      <br>
      James McD.
      <br>
      <br>
      <br>
      <br>
      _______________________________________________
      <br>
      Linux-users mailing list
      <br>
      <a class="moz-txt-link-abbreviated" href="mailto:Linux-users@linux-sxs.org">Linux-users@linux-sxs.org</a>
      <br>
      <a class="moz-txt-link-freetext" href="http://mailman.celestial.com/mailman/listinfo/linux-users">http://mailman.celestial.com/mailman/listinfo/linux-users</a>
      <br>
    </blockquote>
    <br>
  </body>
</html>