Bit operation is a unary and two-dollar operation of the bitwise or binary number of the bit-mode in the program design. On many ancient microprocessors, bit operations are slightly faster than addition and subtraction, and the bitwise operations are much faster than the multiplication algorithm. In modern architectures, this is not the case: bit operations are usually the same as the addition operation (still faster than multiplication)
Cons: can only be integer and character type data
Bit operations are mainly for binary computing operations, which are: with & , non-!, or | , xor or ^ , shift left > and right Shift <
1. and &
The following rules apply: The two operands have a bit of 1, the result is 1, otherwise the result is 0, for example:
1&1=1
1&0=0
0&1=0
0&0=0
---
001
101
---------------
001 (Result)
Conclusion 1: two numbers A and B (0<a<b) and its result range are [0,a], including 0 and a
Scenario: HashMap the size of the hashcode and map arrays minus one and manipulate it to get the position angle of the key in the array.
2. xor ^
Conclusion 1: Two The same number is different or the result is 0
Scenario: Storm Arck mechanism that uses this action to determine whether a task is complete.
Others: http://wenwen.m.sogou.com/mq/qudetail.jsp?qid=606323001&w=c%E8%AF%AD%E8%A8%80%E7%9A%84%E8%B4%9F%E5%80% Bc%e7%9c%8b%e4%b8%8d%e6%87%82&g_ut=3
Baidu Encyclopedia: http://baike.baidu.com/view/379209.htm
Introduction to Java Bit operators