Ordinary bit computing

#include <stdio.h> int main ( void ) 
{ // definition of an unsigned character variable, this variable is only used to store unsigned 
    unsigned char Result; int A, B, C, D; 
    A = 2 ; 
    B = . 4 ; 
    C = . 6 ; 
    D = . 8 ; // the variables are "bitwise aND" operation 
    Result = A & C; 
    the printf ( " Result = D% \ n- " , Result);    // 2 // variables a "bitwise oR" operation 
    Result = B | D; 
    the printf (


    


    

    

    " Result = D% \ n- " , Result);    // 12 is 

    // the variables are "bitwise exclusive or" operation 
    Result = A ^ D; 
    the printf ( " Result = D% \ n- " , Result);    // 10 

    // the variables are "inverted" operation 
    Result = ~ a; 
    the printf ( " Result = D% \ n- " , Result);    // 253 

} 

/ * * 
    bitwise aND (&) operator: to participate in two operations operator, if is 1, then the bit is 1, otherwise 0 
    bitwise oR (|) operators: two corresponding bits as long as there is a 1, then the 1-bit result of 
    bitwise exclusive or ( ^) operator: computing two respective participants, the result is the same number of 0 (false), the result is a different number (true) 
    negation (~) operator: he is a monocular (RMB) operator , used to a binary bitwise, about to 0 to 1, 1 to 0. 

    be careful:
       - bitwise operation is in binary bit, and then converts the decimal number to binary related operations in accordance with the above rules. 
       - bitwise negation operator in addition, the other are binary operator, require both sides have a variable 
       - bit byte operators are bits in a byte or test set Alternatively shift processing, is directed to herein in terms of bytes or words c int char and standard data types, therefore, not be used for bit manipulation float, double, long double, void, and other complex types 
* /

 

Guess you like

Origin www.cnblogs.com/starshine-zhp/p/12381367.html