Skip to content

Instantly share code, notes, and snippets.

@ayende
Created March 26, 2013 21:24
Show Gist options
  • Select an option

  • Save ayende/5249408 to your computer and use it in GitHub Desktop.

Select an option

Save ayende/5249408 to your computer and use it in GitHub Desktop.
Two code samples showing differences between shift operators in C# & C++ Any idea why?
uint32_t x = 25426435u;
std::cout << x << std::endl;
uint32_t a = (x >> 17);
uint32_t b = (x << 15);
std::cout <<a << " " << b << " " << (a | b) << std::endl;
//OUTPUT:
// 25426435
// 193 4244733952 4244734145
uint x = 254262435u;
Console.WriteLine(x);
uint a = (x >> 17);
uint b = (x << 15);
Console.WriteLine(a + " " + b+ " " + (a | b));
// OUTPUT:
// 254262435
// 1939 3729883136 3729885075
@rarous
Copy link

rarous commented Mar 26, 2013

x in cs file has different value. there is 2 between 6 and 4.

@rossipedia
Copy link

Yup, that's it.

@flq
Copy link

flq commented Mar 27, 2013

So, SELECT isn't broken then? Damn...!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment