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
2 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Mike GoldRank #50 · 30.6K reputationPosted Jun 18, 2007, 3:29 PM EDT
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();
}
AlanRank #669 · 3.6K reputationPosted Jun 19, 2007, 2:14 AM EDT
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.