Basic course of C language (ii) data types, variables, and operators (17)

Source: Internet
Author: User
Tags bitwise bitwise operators logical operators
5.3 Bitwise Operators
The difference between Turbo C and other advanced languages is that it fully supports bitwise operators. This is somewhat similar to the bit operation of assembly language.
The bitwise operators in Turbo C are:
━━━━━━━━━━━━━━━━━━━━━━━━━━━━
operator function
────────────────────────────
& Bit Logic and
| Bit logic or
^ Bit logical xor or
-bit logic counter
>> Move Right
<< Move Left
━━━━━━━━━━━━━━━━━━━━━━━━━━━━
Bitwise operations are the detection, setting, or shift of the actual bits in a byte or word, which apply only to character and integer variables and their variants, and are not applicable to other data types.
The result of relational and logical operation expressions can only be 1 or 0. The result of bitwise operations can be a value other than 0 or 1.
Be aware of the difference between bitwise and logical operators, for example, if x=7, the X&&8 value is true (two non-0 values are still not 0), and the X&8 value is 0.
The shift operator ">>" and "<<" refers to moving each digit in a variable to the right or left, usually in the form of:
Move right: Variable name >> number of bits shifted
Move left: Variable name << number of bits shifted
After the shift, the bits at one end are "squeezed out" and the vacated bits on the other end are filled with 0, so the shift in Turbo C is not circular.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.