Computer Science Question
James McDonald
james at jamesmcdonald.id.au
Tue Nov 18 01:04:21 PST 2014
Yes this is what I think I'm after....
*http://en.wikipedia.org/wiki/Bit_array
*On 18/11/14 17:44, Rick Forrister wrote:
> In C++ I found the following code sample:
>
>
>
> Nobody mentioned the Standard C++ Library: |std::bitset<N>|
> <http://www.sgi.com/tech/stl/bitset.html>.
> Or the boost version: |boost::dynamic_bitset|
> <http://www.boost.org/doc/libs/1_36_0/libs/dynamic_bitset/dynamic_bitset.html>.
>
> No need to roll your own:
>
> |#include <bitset>
> #include <iostream>
>
> int main()
> {
> std::bitset<5> x;
>
> x[1] = 1;
> x[2] = 0;
> // Note x[0-4] valid
>
> std::cout<< x<< std::endl;
> }|
>
>
> and you could map them more or less as follows:
> sex=m|f=0|1
> mood=h|s=0|1
> mature=a|c=0|1
> color=r|b=0|1
> handed=r|l=0|1
> Thus, a female child who is happy, likes re and is right handed would
> encode to: 10100
>
> in PDP-11 assembler there's a BSB command (bit set byte), and you can
> embed assembler in C functions.
>
> Hope it helps
> RickF
>
> On 11/17/2014 9:28 PM, James McDonald wrote:
>> Hi All,
>>
>> I am wondering how to do the following:
>>
>> Say I have a list of values I want to assign to a person e.g.
>>
>> 1. Male
>> 2. Female
>> 3. Happy
>> 4. Sad
>> 5. Child
>> 6. Red is favorite color
>> 7. Blue is favorite color
>> 8. RIght handed
>> 9. Left handed
>> etc.
>>
>> 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?
>>
>> 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
>>
>> My problem is I can't figure out what to Google to teach myself how
>> to do it.
>>
>> Can anyone point me in the right direction?
>>
>> Thanks.
>> James McD.
>>
>>
>>
>> _______________________________________________
>> Linux-users mailing list
>> Linux-users at linux-sxs.org
>> http://mailman.celestial.com/mailman/listinfo/linux-users
>
>
>
> _______________________________________________
> Linux-users mailing list
> Linux-users at linux-sxs.org
> http://mailman.celestial.com/mailman/listinfo/linux-users
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mailman.celestial.com/pipermail/linux-users/attachments/20141118/91e18199/attachment-0001.html>
More information about the Linux-users
mailing list