Home > Backend Development > C#.Net Tutorial > What are the bitwise operators in C language?

What are the bitwise operators in C language?

coldplay.xixi
Release: 2020-10-30 14:42:15
Original
6946 people have browsed it

The bitwise operators in C language are: 1. [&] bitwise AND; 2. [|] bitwise OR; 3. [^] bitwise XOR; 4. [~] negation; 5. [<<] Move left; 6. [>>] Move right.

What are the bitwise operators in C language?

[Related learning recommendations: C language tutorial video]

The bitwise operators in C language are:

Bitwise operations are unary and binary operations on bitwise or binary numbers in bit mode in programming.

On many older microprocessors, bit operations are slightly faster than addition and subtraction operations, and usually bit operations are much faster than multiplication and division operations.

In modern architectures, this is not the case: bitwise operations often operate at the same speed as addition operations (still faster than multiplication operations).

Bit operators are used to operate on binary bits. Java provides bit operators as shown in the following table: Among the bit operators, except ~, the rest are binary operators.

The operands can only be integer and character data.

Six bitwise operators in C language:

  • & Bitwise AND

  • | Bitwise OR

  • ^ Bitwise XOR

  • ~Negation

  • << ;Shift left

  • ##>>Shift right

The bitwise AND operator "&" is a binary operator. Its function is to perform the binary AND of the corresponding two numbers involved in the operation. Only when the corresponding two binary bits are both 1, the result bit is 1, otherwise it is 0. The numbers involved in the operation appear in two's complement format.

For example: 9&5 can be written as follows: 00001001 (two's complement of 9)&00000101 (two's complement of 5) 00000001 (two's complement of 1) It can be seen that 9&5=1. The bitwise AND operation is usually used to clear some bits to 0 or retain some bits. For example, by clearing the high eight bits of a to 0 and retaining the low eight bits, the a&255 operation can be performed (the binary number of 255 is 11111111).

main()
{
    int a=9,b=5,c;
    c=a&b;
    printf("a=%d\nb=%d\nc=%d\n",a,b,c);
}
Copy after login

The above is the detailed content of What are the bitwise operators in C language?. 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