如何进行按位&放大器; (AND)工作在Java? [英] How Does The Bitwise & (AND) Work In Java?

查看:127
本文介绍了如何进行按位&放大器; (AND)工作在Java?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我是通过一些code例子阅读和跨&放出来; 在Oracle自己的位运算和移位操作页面上的网站。在我看来,这并没有做的工作,解释按位&放太清楚; 。据我所知,它直接做一个操作该位,但我只是不知道什么样的操作,我想知道该操作是什么。下面是我下车甲骨文网站的一个示例程序:<一href=\"http://docs.oracle.com/javase/tutorial/display$c$c.html?$c$c=http://docs.oracle.com/javase/tutorial/java/nutsandbolts/examples/BitDemo.java\">http://docs.oracle.com/javase/tutorial/display$c$c.html?$c$c=http://docs.oracle.com/javase/tutorial/java/nutsandbolts/examples/BitDemo.java

I was reading through some code examples and came across a & on Oracle's website on their Bitwise and Bit Shift Operators page. In my opinion it didn't do too well of a job explaining the bitwise &. I understand that it does a operation directly to the bit, but I am just not sure what kind of operation, and I am wondering what that operation is. Here is a sample program I got off of Oracle's website: http://docs.oracle.com/javase/tutorial/displayCode.html?code=http://docs.oracle.com/javase/tutorial/java/nutsandbolts/examples/BitDemo.java

推荐答案

这是整数重新presented作为存储位的序列。用于与人类交互,计算机具有显​​示它作为十进制数字,但所有的计算都以二进制进行。 123 以十进制存储为 1111011 在内存中。

An integer is represented as a sequence of bits in memory. For interaction with humans, the computer has to display it as decimal digits, but all the calculations are carried out as binary. 123 in decimal is stored as 1111011 in memory.

&安培; 运算符是一个按位与。其结果是,在两个数字接通的比特。 1001安培; 1100 = 1000 ,因为只有第一位在这两个打开的。

The & operator is a bitwise "And". The result is the bits that are turned on in both numbers. 1001 & 1100 = 1000, since only the first bit is turned on in both.

| 操作符是按位或。其结果是,在任一的数字接通的比特。 1001 | 1100 = 1101 ,因为只有从右边第二位是两个零。

The | operator is a bitwise "Or". The result is the bits that are turned on in either of the numbers. 1001 | 1100 = 1101, since only the second bit from the right is zero in both.

也存在 ^ 运营商,这是按位异或和位不分别。最后,还有的&LT;&LT; &GT;&GT; &GT;&GT;方式&gt; 移位运算

There are also the ^ and ~ operators, that are bitwise "Xor" and bitwise "Not", respectively. Finally there are the <<, >> and >>> shift operators.

引擎盖下, 123 存储为两种 01111011 00000000 00000000 00000000 00000000 00000000 00000000 01111011 取决于系统。使用位运算符,从而重新presentation用于不要紧,因为这两个重presentations作为逻辑处理数 00000000000000000000000001111011 。剥离了前导零叶 1111011

Under the hood, 123 is stored as either 01111011 00000000 00000000 00000000 or 00000000 00000000 00000000 01111011 depending on the system. Using the bitwise operators, which representation is used does not matter, since both representations are treated as the logical number 00000000000000000000000001111011. Stripping away leading zeros leaves 1111011.

这篇关于如何进行按位&放大器; (AND)工作在Java?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆