Connecting Tech Pros Worldwide Forums | Help | Site Map

Negative int to positive ulong?

Curt Krueger
Guest
 
Posts: n/a
#1: Nov 16 '05


I'll spare you the details of why we need this, but what I'm needing to do
is convert -9999 to a positive ulong value.

Any code examples or ideas on how to do this, where to look?

thanks,
Curt



JaD
Guest
 
Posts: n/a
#2: Nov 16 '05

re: Negative int to positive ulong?


int x = -9999;
ulong y = (ulong)Math.Abs(x);

"Curt Krueger" <ckrueger@DONOTRY.com> wrote in message
news:eBAf3wveEHA.708@TK2MSFTNGP09.phx.gbl...[color=blue]
>
>
> I'll spare you the details of why we need this, but what I'm needing to do
> is convert -9999 to a positive ulong value.
>
> Any code examples or ideas on how to do this, where to look?
>
> thanks,
> Curt
>
>[/color]


Jon Skeet [C# MVP]
Guest
 
Posts: n/a
#3: Nov 16 '05

re: Negative int to positive ulong?


Curt Krueger <ckrueger@DONOTRY.com> wrote:[color=blue]
> I'll spare you the details of why we need this, but what I'm needing to do
> is convert -9999 to a positive ulong value.
>
> Any code examples or ideas on how to do this, where to look?[/color]

int x = -9999;
ulong y = unchecked((ulong)x);
Console.WriteLine(y);

prints out 18446744073709541617 - is that what you're after?

--
Jon Skeet - <skeet@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Curt Krueger
Guest
 
Posts: n/a
#4: Nov 16 '05

re: Negative int to positive ulong?


[color=blue][color=green]
> > Any code examples or ideas on how to do this, where to look?[/color]
>
> int x = -9999;
> ulong y = unchecked((ulong)x);
> Console.WriteLine(y);
>
> prints out 18446744073709541617 - is that what you're after?
>
> --
> Jon Skeet[/color]

Yes it is, thank you very much guys!

Curt


Closed Thread