Bitwise Operators & | ^ >> << Introduction

Source: Internet
Author: User

These days to see the algorithm into a bit operation because it is not used a little bit, someone should be the same as me.
This time I collected a few notes briefly, I hope we all add

The so-called bitwise operations are binary operations.
& If it is two people are very familiar with, "&&" is "with", one is also
is just two binary code "and", two are "1" will get "1"
00001001
&
00000101
=
00000001


All the others are "| |" Is "or", two as long as one is "1" will get "1"
00001001
|
00000101
=
00001101
This is not commonly used, "^" Two are "1" to "0", from one is "1" to "1"
00001001
^
00000101
=
00001100


>> << is displacement
How many digits to the left and right after the number is converted to binary
Cases:
14>>2=3
00001100 (14)
>>2
00000011 (3)
If it's gone, leave it.
3>>1=1
3>>2=0
00000011 (3)
>>1
00000001 (1)
"<<" is moving forward.
3<<2 = 14
00000011 (3)
<<2
00001100 (14)

This article is from the My database blog, so be sure to keep this source http://wyd51.blog.51cto.com/1549780/1793106

Bitwise operators & | ^ >> << Introduction

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.