First, we need to understand how the numbers are stored in the computer.
In 68, for example, his binary is (68) 2=1000100. What about 68? Because the integers in the computer are in the complement notation (the complement is the original code plus one), so-68 is actually 68 bitwise inverse, the end plus a later result. The following table (ignores symbol bits):
Original Code 1 0 0 0 1 0 0
↓
Anti-code 0 1 1 1 0 1 1
↓
Complement 0 1 1 1 1 0 0
Let's put (68) 2 and (-68) 2 together and take a look:
1 0 0 0 1 0 0
0 1 1 1 1 0 0
found that the 0 of their end bands were as much. So lowbit (x) =x&-x. (& is converted into binary and then performed and calculated, and && is directly performed and calculated)
Here is a more classic tree-like Array (BIT):
↓↓↓↓↓
Lowbit = 24 23 22 21 20
The following rules can be obtained:
1) For node I, if he is the left Dial hand node (bottom left upper right), then the number of his parent node is i+lowbit (i); if he is the right child node, the number of his parent node is i-lowbit (i). (I>=lowbit (i))
2) The odd lowbit are all 1 because their binary bits are 1 (that is, the factor is not 2). The following and so on: 2, 6, 10, 14 can be divisible by 21, 4, 12 divisible by 22 ... So their lowbit are 2, 3 ...
On the basis of the above rules, we create a new array C (A is the original array), it is easy to get:
Ci=ai-lowbit (i) +1+ai-lowbit (i) +2+......+ai
Example: C1=a1,c2=a1+a2,c3=a3,c4=a1+a2+a3+a4,......
Tree-like array