What is the logic that follows. I can not understand why this
int a = 0x0c;
a &= 0x05;
return this
4
I understand the hexadecimal numbers only that I do not understand the logic of the AND between integers
What is the logic that follows. I can not understand why this
int a = 0x0c;
a &= 0x05;
return this
4
I understand the hexadecimal numbers only that I do not understand the logic of the AND between integers
If you pass the values to binary
0x0C = 1 1 0 0
0x05 = 0 1 0 1
And you apply the AND logical operator where:
1 AND 1 = 1
1 AND 0 = 0
0 AND 0 = 0
The result is:
1 1 0 0
AND 0 1 0 1
-------
0 1 0 0
That in decimal is = 4 and in hexadecimal = 0x04
An expression that uses the assignment operator & = for example x & = y, is equivalent to
x = x & and
Your numbers are Hexadecimals representing 12 and 5 respectively