Changing Bits in Flag Words
Writing, reading or toggling bits in flags can be done only using the OR, AND and NOT operations - operations which can be performed quickly in the processor.
To set a bit, OR the status byte with a mask byte. Any bits set in the mask byte or the status byte will be set in the result.
int setBit(int val, int bit_position) { return val | (1 << bit_position); }To clear a bit, perform a NOT operation on the mask byte, then AND it with the status byte. The result will have the appropriate flag cleared (set to 0).
int clearBit(int val, int bit_position) { return val & ~(1 << bit_position); }To toggle a bit, XOR the status byte and the mask byte. This will set a bit if it is cleared or clear a bit if it is set.
int toggleBit(int val, int bit_position) { return val ^ (1 << bit_position); }Read more about this topic: Flag Word
Famous quotes containing the words changing, bits, flag and/or words:
“The aim of science is to apprehend this purely intelligible world as a thing in itself, an object which is what it is independently of all thinking, and thus antithetical to the sensible world.... The world of thought is the universal, the timeless and spaceless, the absolutely necessary, whereas the world of sense is the contingent, the changing and moving appearance which somehow indicates or symbolizes it.”
—R.G. (Robin George)
“On their slag heap, these children
Wear skins peeped through by bones and spectacles of steel
With mended glass, like bottle bits in slag.”
—Stephen Spender (19091995)
“My dream is that as the years go by and the world knows more and more of America, it ... will turn to America for those moral inspirations that lie at the basis of all freedom ... that America will come into the full light of the day when all shall know that she puts human rights above all other rights, and that her flag is the flag not only of America but of humanity.”
—Woodrow Wilson (18561924)
“Mothers who have little sense of their own minds and voices are unable to imagine such capacities in their children. Not being fully aware of the power of words for communicating meaning, they expect their children to know what is on their minds without the benefit of words. These parents do not tell their children what they mean by good much less why. Nor do they ask the children to explain themselves.”
—Mary Field Belenky (20th century)