Extending OG's response. By Bitwise AND operation means here:
uint a = 0b_1111_1000;
uint b = 0b_1001_1101;
uint c = a & b;
Console.WriteLine(Convert.ToString(c, toBase: 2));
Quote:
For bool operands, the & operator computes the logical AND of its operands.
The unary & operator is the address-of operator
Refer:
Bitwise and shift operators - C# reference | Microsoft Docs[
^]
Bitwise operators in Java - GeeksforGeeks[
^]
To explain it further:
Quote:
The output of bitwise AND is 1 if the corresponding bits of two operands is 1. If either bit of an operand is 0, the result of corresponding bit is evaluated to 0.
Let us suppose the bitwise AND operation of two integers 12 and 25.
12 = 00001100 (In Binary)
25 = 00011001 (In Binary)
Bit Operation of 12 and 25
00001100
00011001
========
00001000 = 8 (In decimal)
Via code:
{
int a = 12, b = 25, c;
c = a&b;
Console.Writeline("Output = "+c);
}
So overall, your n &= n-1 translates to:
n = n & n-1
In it, value of n=5 is getting reset to:
n = number(bit(5) & bit(4))
=> n = number((0101) & (0100))
0101
0100
======
0100
=> n = number ( 0100 ) = 4
Hope that clarifies.