First of all, I want to know if this is possible: let s say I have an unsigned long which contains some abritrary unsigned shorts, which may or may not be in the number. For example:
unsigned short int id1 = 3456,
id2 = 30998;
unsigned long long bitfld = id1|id2;
Can the other 2 fields be assumed as 0? And is OR the right operation for this? After that let s say I pass bitfld as an argument:
void dostuff (unsigned long long bf)
{
//pseudo code
if( the first field exists in bf)
get first field;
if( the second field exists in bf)
get second field;
//etc...
}
I think I have to poll out the first 16 bits of the bitfield and check those, then recursively poll them, verify them and store them if they are greater than 0. But I m not sure how to do this, bit shifting only shifts left or right, thus, it only divides or multiplies right?
sorry for the bump. Thanks all for your answers, but I ended up using a simpler and more efficient method, an internal structure. You see, I could have done this easily with a string, but my purpose was transparency to the user of the code, easy to program so to say. I created an internal structure to hold my values and then a public method to create and return such structure, so it is easy to use and faster to parse (though it has the overhead of allocating in the stack a (albeit small) structure, which the bit field solution hasn t, but alas).
So thank you all for your answers.