[Mono-dev] Oddity in C#
Alan McGovern
alan.mcgovern at gmail.com
Fri Jun 29 16:12:27 EDT 2007
The MSDN documentation for "Read" might help here...
http://msdn2.microsoft.com/en-us/library/system.console.read.aspx
What you'll need to do is read in the console input as a string and use
Convert.ToInt32() (or whatever) to get the input value.
Alan.
On 6/28/07, Paul F. Johnson <paul at all-the-johnsons.co.uk> wrote:
>
> 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/
>
> _______________________________________________
> Mono-devel-list mailing list
> Mono-devel-list at lists.ximian.com
> http://lists.ximian.com/mailman/listinfo/mono-devel-list
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.ximian.com/pipermail/mono-devel-list/attachments/20070629/74ba0e61/attachment.html
More information about the Mono-devel-list
mailing list