[Mono-dev] Oddity in C#
Paul F. Johnson
paul at all-the-johnsons.co.uk
Thu Jun 28 07:37:44 EDT 2007
Hi,
Got a bit of a strange one which I'm not sure about. Below is a bit of code
I'm playing with...
namespace bitcount
{
public bitcount
{
private uint BitCounter(uint u)
{
uint uCount;
uCount = u - ((u >> 1) & 033333333333) - ((u >> 2) & 011111111111);
return (uCount + (uCount >> 3) & 030707070707 % 63;
}
public static void Main
{
bitcount bc = new bitcount();
uint number;
Console.WriteLine("Please enter a number ");
number = Console.Read();
number = BitCounter(number);
Console.WriteLine(number);
Console.ReadKey();
}
}
}
Okay, it won't compile (Read is static int for a start), but the oddest piece
of the puzzle is that the uint variables cause problems when I try to compile
(casting). If I change everything to long, the value returned is incorrect (if
you re-write this in C or C++ and enter 85, it returns 2, in C# it returns 33).
Any clues as to why this behaviour is seen? It makes no difference if I target
mono or VS.NET.
TTFN
Paul
--
Get your free @ukpost.com account now
http://www.ukpost.com/
More information about the Mono-devel-list
mailing list