c language bit operators

Release: 2019-10-25 16:27:13
Original
16414 people have browsed it

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;
Copy after login

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;
Copy after login

3, "^"

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

0^0=0;   
0^1=1;   
1^0=1;  
1^1=0;
Copy after login

4, "~"

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

~1=0;  
~0=1;
Copy after login

5, "<<"

Binary left shift operator. Shift all the binary bits of an operand to the left by a certain number of bits (the left bit is discarded and the right bit is filled with 0).

A << 2 will get 240, which is 1111 0000

6, ">>"

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template