Saturday 15 May 2010

bit manipulation - How Does The Bitwise & (AND) Work In Java? -


I was reading through some code examples and on the Oracle's website, on their bitwise & amp; and the bit shift operator page. In my opinion, this is called BitWord & amp; The job was not very good, I understand that it does the operation directly, but I am not sure what kind of operation, and I am thinking about what the operation is. Here is a sample program that I got from Oracle's website:

"post-text" itemprop = "text">

An integer of the sequence of bits As shown in the form of remembrance. To communicate with humans, the computer has to display it in decimal form, but all calculations are done in binary form. 123 is stored in memory in 1111011 .

& amp; The operator is a bitwise "and" the result is the bits that are running in both numbers. 1001 & amp; 1100 = 1000 , since only both bits are turned on in both.

| The operator is a bitwise "or" the result is the bits that turn into any of the numbers. 1001 | 1100 = 1101 , since the correct second only has zero in both.

There are also ^ and ~ operators, respectively, which are "Xor" and "not", respectively. Finally & lt; & Lt; , & gt; & Gt; and & gt; & Gt; & Gt; are shift operators.


Under the hood, either 123 is either 01111011 000000000000000000000000 or 00000000 00000000 00000000 01111011 on the system depends on. Using bitwise operators, the representation that is used, does not matter, because both convergence is considered as logical number as 00000000000000000000000001111011 . The leading zero zero leaves 1111011 .

No comments:

Post a Comment