iOS Development Learning Record the 9th day of C language learning-----bit arithmetic

Source: Internet
Author: User

One, bit operation introduction

1, operator:& | ^ ~ << >>

Use: direct operation of binary, save memory, high efficiency.

Note Only the integer operand (char, short,int, long) arithmetic rule can be used:

1) & Bitwise AND full 1 only 1 otherwise 0: only the corresponding two binary are 1 o'clock, the result bit is 1, otherwise 0 with 6 and 3 This example.

#include <stdio.h>int main (int argc, const char * argv[]) {    //define two integer variables, do bitwise AND, bitwise OR, bitwise XOR, left SHIFT, right shift    int num1=8 , num2=3;        printf ("Bitwise AND%d\n", num1&num2);//The result is: 0        printf ("Bitwise OR%d\n", num1|num2);//Result:        printf ("Bitwise XOR or%d\n", num1^ NUM2);//results are:        printf ("Left Shift%d\n", num1<<num2);//Result:        ("Shift right%d\n", num1>>num2);//Result: 1        return 0;}

iOS Development Learning Record the 9th day of C language learning-----bit arithmetic

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.