[C++] instantiating bitset using hex character.
- by bndz
Hey, I'm trying to figure out how to instantiate a 4 bit bitset based on a hex character. For instance, If I have a character with value 'F', I want to create a bitset of size 4 initialized to 1111 or if it is A, i want to initialize it to 1010. I could use a bunch of if statements like so:
fn(char c)
{
bitset<4 temp;
if(c == 'F')
temp.set();
//...
if(c == '9')
{
temp.set(1);
temp.set(3);
}
//...
}
This isn't efficient, is there a way of easily converting the string to a decimal integer and constructing the bitset using the last 4 bits of the int?
Thanks for any help.