惯性聚合 高效追踪和阅读你感兴趣的博客、新闻、科技资讯
阅读原文 在惯性聚合中打开

推荐订阅源

T
Tailwind CSS Blog
大猫的无限游戏
大猫的无限游戏
L
LINUX DO - 热门话题
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
雷峰网
雷峰网
aimingoo的专栏
aimingoo的专栏
博客园_首页
MongoDB | Blog
MongoDB | Blog
V
V2EX
GbyAI
GbyAI
量子位
Microsoft Azure Blog
Microsoft Azure Blog
有赞技术团队
有赞技术团队
G
Google Developers Blog
云风的 BLOG
云风的 BLOG
B
Blog
Microsoft Security Blog
Microsoft Security Blog
S
SegmentFault 最新的问题
O
OpenAI News
N
News and Events Feed by Topic
博客园 - Franky
爱范儿
爱范儿
Forbes - Security
Forbes - Security
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
V2EX - 技术
V2EX - 技术
Application and Cybersecurity Blog
Application and Cybersecurity Blog
N
News and Events Feed by Topic
N
News | PayPal Newsroom
Schneier on Security
Schneier on Security
Cloudbric
Cloudbric
Security Archives - TechRepublic
Security Archives - TechRepublic
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
Recent Commits to openclaw:main
Recent Commits to openclaw:main
人人都是产品经理
人人都是产品经理
P
Privacy International News Feed
Cyber Security Advisories - MS-ISAC
Cyber Security Advisories - MS-ISAC
B
Blog RSS Feed
阮一峰的网络日志
阮一峰的网络日志
D
DataBreaches.Net
Last Week in AI
Last Week in AI
罗磊的独立博客
Spread Privacy
Spread Privacy
Recent Announcements
Recent Announcements
The Cloudflare Blog
Google DeepMind News
Google DeepMind News
AWS News Blog
AWS News Blog
The Register - Security
The Register - Security
Y
Y Combinator Blog
J
Java Code Geeks
I
Intezer

博客园 - Adair

Dojo Style Guide Dojo Javascript 编程规范(转) dojo1.7 加载器 ArcGIS Server GP服务使用常见错误总结 JavaScript prototype原型链介绍 网址收藏 新一轮互联网创投潮再次掀起 学习一下别人的翻译 创意空间 富翁的西瓜 8个实用保健偏方 给你健康好身体 冬季巧食生姜可提高免疫力 How to set the DefaultButton in a Page Based on ASP.NET Master Page wz_tooltip使用备忘 如何通过饮食来提高免疫力 AjaxToolKit学习笔记 之 AjaxToolKit.dll For ASP.NET2.0 下载 AjaxToolKit学习笔记 之 Accordion AjaxToolKit学习笔记 之 TextBoxWatermark AjaxToolKit学习笔记 之 TabContainer
位运算
Adair · 2014-10-20 · via 博客园 - Adair

& 与

| 或

^ 异或

~ 取补

<< 左移

>> 右移

其中取补只有一个操作数而其它的位操作符都有两个操作数。这些运算都不会产生溢出位。操作符的操作数为整型或者是可以转换为整型的任何其它类型。

  • 与运算

操作数按二进制位进行与运算,运算规则为:

0&0=0

0&1=0

1&0=0

1&1=1

这说明除了两个位均为1, 与运算结果为1。 其它情况下与运算结果均为0。

比如2 和10 进行与运算,2 的二进制表示 00000010,10 的二进制表示 00001010, 与运算的结果 00000010, 所以2&10 的结果为2

  • 或运算

操作数按二进制位进行或运算,运算规则为:

0|0=0

0|1=1

1|0=1

1|1=1

这说明除了两个位均为0, 或运算结果为0; 其它情况下或运算结果均为1。

比如2 和10 进行或运算, 2 的二进制表示 00000010, 10 的二进制表示 00001010, 或运算的结果 00001010 。所以2|10 的结果为10。

  • 异或运算

操作数按二进制位进行异或运算。运算规则为:

0^0=0

0^1=1

1^0=1

1^1=0

这说明当两个位相同时,异或运算结果为0。 不相同时异或运算结果为1。

比如 2 和10 进行异或运算, 2 的二进制表示 00000010, 10 的二进制表示 00001010, 异或运算的结果 00001000, 所以2^10 的结果为8

  • 取补运算

取补运算对操作数的每一位取补. 如对10 取补结果为: 10 的二进制表示 00001010 与运算的结果 11110101

  • 左移运算

位左移运算将整个数按位左移若干位,左移后空出的部分0。比如:8位的byte型变量

byte a=0x65(即二进制的01100101),将其左移3位:a<<3的结果是0x27(即二进制的00101000)。

  • 右移运算

位右移运算将整个数按位右移若干位,右移后空出的部分填0。比如:8位的byte型变量

Byte a=0x65(既(二进制的01100101))将其右移3位:a﹥﹥3的结果是0x0c(二进制00001100)。