Dark Horse Programmer---C language---memory profiling

Source: Internet
Author: User

------iOS training, Java training, Android training, iOS learning technology blog, looking forward to communicating with you------

Bitwise AND &

1101110 101101

0110101 000100

——————— ---------------

0100100 000100

in situ and 1&, remained unchanged; and 0&, all 0

Therefore, you can let the original number of a bit with 1&, according to the result can determine whether the bit is 0 or 1, and the result is only 0 or 1

A&1==1//a is odd because the last digit of the odd number is 1.

A&1==0//a is even, because the last digit of the even number is 0.

outputs a binary form of an integer

void printbinary (int num) {

// with the right shift, each bit of &1 Gets the value of each bit printed

// define variables, record the number of bits that are shifted right

// right Shift after &1 bit gets the first bit value 0 or 1

//(sizeof (num) <<3) -1==4*8-1==31

for ( int count= (sizeof) <<3)-1; count>=0; count-- ) {

printf ("%d",(num>>count) &1); any number &1 results can only be 0 or 1

If (! ( count%4)) {

printf ("");

If (! ( count%8)) {

printf ("");

}

}

}

printf ("\ n");

}

Bitwise OR |

010110 101101

011100 000000

——————— ---------------

011110 101101

A|0=a

Bitwise XOR or ^

Each one is 0 and the difference is 1. and can be exchanged

A^b^c==a^c^b==b^a^c

A^a==0

A^0==a

A^b^a==b

The interchange A^b^a==a^a^b==0^b==b of A and B values using bitwise XOR or ^ operations

A=a^b;

B=a^b;

A=a^b;

Shift left <<

a<<n==a*2 N-Th square

But left shifts can lead to positive and negative changes.

Shift Right >>

A>>N==A/2 N-Th square

Positive and negative changes

Dark Horse Programmer---C language---memory profiling

Related Article

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.