Question

An Int64 variable needs to be shifted. I am parsing pseudo mathematical functions from a database file. The Variables are uint32 or int32 so i did put them into an Int64 to handle them equally without loosing anything. In one of my treenodes i need to bitshift Int64.

Unfortunately the shift operator does not apply to Int64. Is there a standard way of bit shifting Int64 that i am not aware of?

//Int32 Example works
int a32 = 1;
int b32 = 2;
int c32 = a32 >> b32;

//Int64 Example does not compile
Int64 a64 = 1;
Int64 b64 = 2;
Int64 c64 = a64 >> b64; //invalid operator
Était-ce utile?

La solution

I believe the right-hand operand of the right-shift operator (in C#) always takes an int, even if the left-hand operand is not an int.

Official details here in C# Specification on MSDN.

Autres conseils

The number of bits to be shifted must be an int.

Eg:

int shift = 3;
long foo = 123456789012345;
long bar = foo >> shift;
Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top