Trying to Rightshift 32 Bits
why does
[code]8103936 >> 32[/code]
return 8103936?
I need it to return 0, like it should. How do I fix
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
AlanPosted Jun 19, 2007, 6:14 AM
32 is, of course, 100000 in binary and so 0 bits are shifted and therefore the unchanged number is returned.
For a 64 bit number, the 6 low order bits are significant and we can therefore shift up to 63 bits before we start again at 0, which is why Mike's approach works.
Mike GoldPosted Jun 18, 2007, 7:29 PM
static void Main(string[] args)
{
long val1 = 8103936;
int shift = 32;
long val = val1 >> shift;
Console.WriteLine("The value of {0} right shifted {1} is {2}.", val1, shift, val);
Console.ReadLine();
}