How to connect a bit to a number?

7

There are situations where we use numbers to load flags , meaning each bit, or set of bits, means something. Or we need to manipulate some data according to their bits, maybe it has to do with colors or something that bits individually end up having a special meaning. In cases like this the simplest way to connect a specific bit knowing in what position it should be. And how to turn it off or reverse its value?

    
asked by anonymous 05.01.2017 / 11:54

1 answer

4

To manipulate bits the most common is to use the operators of | ( or ), & ( and ) and ^ ( xor ), . The shift or bit shift operator is often important to get to the desired bit if what you know is the position of it. These operators are usually present in most languages with the same semantics, so everything that works here should work for other languages. Several questions talk about this:

05.01.2017 / 11:54