1. long int temp;
2. int product = -1;
3. temp = (long int)product & 0xFFFFFFFF;
4. temp = temp << 32;
I know that temp
is 64-bit while product
is 32-bit.
I am slightly confused about lines 3
and 4
.
We are casting product
as a long int
, which means product
should get represented as 64-bit and doing a bitwise AND
with 0xFFFFFFFF
. The hexadecimal representation of 0xFFFFFFFF
is all 1
's, so the AND
should preserve the binary representation of -1
?
Since -1
in binary is 1111111111111111
, would temp
now be 32 1
's followed by 32 0
's, or vice versa? If the former, is there any point to doing the left shift on line 4
?
I am mainly confused about the conversion of 32-bit to 64-bit here and how it looks in binary.