Not sure what the title has to do with the content of your post (C# ?), and I also don’t know where you might think to have any errors.
But in general there is no difference between C++ and C# bitwise operations, as long as you work without pointers.
I feel this is incorrect? Thus, the Bit Wise Operation may not be the same and 32 bit registers may over flow and cause incorrect values being returned.
So yes many of the operations appear to be the same after some testing. However, to build that ‘better mouse trap’ a better way to manage the possibility of int overflow problems would be ideal.
Nice example. I have done some tests and interestingly results are good:
uint number = 0x418;
uint number1 = 0x8041;
uint number2 = 0x1804;
// number >> 4
// (number >> nbits) | (number << (16 - nbits))
int nbits = 0;
for (int i = 0; i < 20; i++)
{
Console.WriteLine("Result: {0:00} Result: {1:00} Where i = {2:00}.", (number1 >> nbits) | (number1 << (16 - nbits)), Convert.ToString(((number1 >> nbits) | (number1 << (16 - nbits))), 16), i);
nbits = i;
}
Console.ReadLine();
Results:
Result: 2151776321 Result: 80418041 Where i = 00.
Result: 2151776321 Result: 80418041 Where i = 01.
Result: 1075888160 Result: 4020c020 Where i = 02.
Result: 537944080 Result: 20106010 Where i = 03.
Result: 268972040 Result: 10083008 Where i = 04.
Result: 134486020 Result: 8041804 Where i = 05.
Result: 67243010 Result: 4020c02 Where i = 06.
Result: 33621505 Result: 2010601 Where i = 07.
Result: 16810752 Result: 1008300 Where i = 08.
Result: 8405376 Result: 804180 Where i = 09.
Result: 4202688 Result: 4020c0 Where i = 10.
Result: 2101344 Result: 201060 Where i = 11.
Result: 1050672 Result: 100830 Where i = 12.
Result: 525336 Result: 80418 Where i = 13.
Result: 262668 Result: 4020c Where i = 14.
Result: 131334 Result: 20106 Where i = 15.
Result: 65667 Result: 10083 Where i = 16.
Result: 32833 Result: 8041 Where i = 17. <---- This is the result that the question was looking for…
Result: 2147483648 Result: 80000000 Where i = 18.
Result: 1073741824 Result: 40000000 Where i = 19.
This also shows that:
does indeed fix this overflow problem.
Thanks!!! +1