The basic bit computing

First, the operation (&)

Bitwise commonly used for binary arithmetic, for example, by calculating ip address subnet mask, as the segment block of the field, the rest of the ip address as

The results of calculation are as follows, both sides are 1, the result is a

0&0=0,0&1=0,1&0=0,1&1=1

Second, the non-operation (~)

I.e. the negation operator NOT operation, variations in the binary 1 1 0,0 variant
the calculation of non 110101
001010 1010 i.e.

Third, OR (|)

As long as both sides of a 1, the result is 1

OR operation as follows

0|0=0,0|1=1,1|0=1,1|1=1

Fourth, the XOR operation

Simple to understand, the same as false, iso true

0^0=0,0^1=1,1^0=1,1^1=0

As can be seen, any number of exclusive OR 0, the result is itself. May also be implemented using XOR a good exchange algorithm for the exchange of two numbers, the algorithm is as follows:

1 a = a ^ b;
2 b = b ^ a;
3 a = a ^ b;

 

Guess you like

Origin www.cnblogs.com/liaopeng123/p/11375561.html