vendredi 30 janvier 2015

Rational comparison of bits

I have a number of type int. It lies within [0,255]. That is, includes 8 bits. I need to check often say:


2(int) = 00000010(Binary)




1. The bit 6 and bit 7 must be equal to 0 and 1 respectively.
And I check it like this:



if ((!(informationOctet_ & (1 << 6))) && (informationOctet_ & (1 << 7)))
{
...
}


But it is not very readable, whether it is possible - to do something "beautiful"? I can not use the std::bitset, my head says it's a waste of resources and you can not do without it.


Aucun commentaire:

Enregistrer un commentaire