Home  >  Article  >  Backend Development  >  c language bit operators

c language bit operators

尚
Original
2019-10-25 16:27:1316413browse

c language bit operators

Bitwise operators allow processing of individual bits within a byte or larger unit of data: any bit or bits can be cleared, set, or inverted. You can also shift the bit pattern of an integer to the right or left.

1. "&"

Bitwise AND operation, perform "AND" operation based on binary bits. Operation rules:

0&0=0;   
0&1=0;    
1&0=0;     
1&1=1;

2, "|"

Bitwise OR operator, perform "OR" operation based on binary bits. Operation rules:

0|0=0;   
0|1=1;   
1|0=1;    
1|1=1;

3, "^"

XOR operator, performs "XOR" operation based on binary bits. Operation rules:

0^0=0;   
0^1=1;   
1^0=1;  
1^1=0;

4, "~"

Negation operator, performs "inversion" operation based on binary bits. Operation rules:

~1=0;  
~0=1;

5, "96ef5a3f369077d16e8f68c26d34bb54>"

Binary right shift operator. Shift all the binary digits of a number to the right by a certain number of bits. Positive numbers are padded with 0s on the left, negative numbers are padded with 1s on the left, and the right sides are discarded.

A >> 2 will get 15, which is 0000 1111

The above is the detailed content of c language bit operators. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Previous article:c++ output statementNext article:c++ output statement