I trying to compile this code:
Int64 itag = BitConverter.ToInt64(temp, 0);
itag &= 0xFFFFFFFFFFFFFC00;
However this gives me the following error:
Operator '&=' cannot be applied to operands of type 'long' and 'ulong'
How do I do this?
See http://msdn.microsoft.com/en-en/library/aa664674%28v=vs.71%29.aspx .
If the literal has no suffix, it has the first of these types in which its value can be represented:
int
,uint
,long
,ulong
.
You have
0xFFFFFFFFFFFFFC00
but Int64.Max is:
0x7FFFFFFFFFFFFFFF
so long
is not big enough and ulong
is taken as the type of the literal.
Now you have on the left side a Int64
, which is signed, and on the right side you have ulong
, however, there is not overload of &=
which accepts that combination, which leads to the error.
C# uses the smallest fitting type for integer literals and 0xFFFFFFFFFFFFFC00 is too big for long so it's an ulong.
So either convert itag to ulong or 0xFFFFFFFFFFFFFC00 to long (unchecked).
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With