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

推荐订阅源

L
LangChain Blog
TaoSecurity Blog
TaoSecurity Blog
cs.CV updates on arXiv.org
cs.CV updates on arXiv.org
SecWiki News
SecWiki News
L
LINUX DO - 最新话题
Google Online Security Blog
Google Online Security Blog
V2EX - 技术
V2EX - 技术
Help Net Security
Help Net Security
Security Latest
Security Latest
T
Troy Hunt's Blog
腾讯CDC
WordPress大学
WordPress大学
cs.AI updates on arXiv.org
cs.AI updates on arXiv.org
钛媒体:引领未来商业与生活新知
钛媒体:引领未来商业与生活新知
H
Hacker News: Front Page
博客园 - 叶小钗
酷 壳 – CoolShell
酷 壳 – CoolShell
雷峰网
雷峰网
T
Threatpost
博客园 - Franky
MongoDB | Blog
MongoDB | Blog
Microsoft Security Blog
Microsoft Security Blog
V
Vulnerabilities – Threatpost
S
Secure Thoughts
M
MIT News - Artificial intelligence
量子位
K
KPMG report finds enterprise disconnect between AI and its ROI | CIO
G
Google Developers Blog
Jina AI
Jina AI
PCI Perspectives
PCI Perspectives
C
Cisco Blogs
罗磊的独立博客
Y
Y Combinator Blog
The GitHub Blog
The GitHub Blog
Last Week in AI
Last Week in AI
让小产品的独立变现更简单 - ezindie.com
让小产品的独立变现更简单 - ezindie.com
CTFtime.org: upcoming CTF events
CTFtime.org: upcoming CTF events
C
Cybersecurity and Infrastructure Security Agency CISA
有赞技术团队
有赞技术团队
Application and Cybersecurity Blog
Application and Cybersecurity Blog
freeCodeCamp Programming Tutorials: Python, JavaScript, Git & More
H
Help Net Security
The Hacker News
The Hacker News
Cyberwarzone
Cyberwarzone
N
News and Events Feed by Topic
aimingoo的专栏
aimingoo的专栏
奇客Solidot–传递最新科技情报
奇客Solidot–传递最新科技情报
J
Java Code Geeks
N
News and Events Feed by Topic
S
Securelist

博客园 - 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)。