473,402 Members | 2,061 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,402 software developers and data experts.

Negative int to positive ulong?



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
Nov 16 '05 #1
3 5378
JaD
int x = -9999;
ulong y = (ulong)Math.Abs(x);

"Curt Krueger" <ck******@DONOTRY.com> wrote in message
news:eB*************@TK2MSFTNGP09.phx.gbl...


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

Nov 16 '05 #2
Curt Krueger <ck******@DONOTRY.com> wrote:
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?


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

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

--
Jon Skeet - <sk***@pobox.com>
http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Nov 16 '05 #3
Any code examples or ideas on how to do this, where to look?


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

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

--
Jon Skeet


Yes it is, thank you very much guys!

Curt
Nov 16 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: pj | last post by:
Why does M$ Query Analyzer display all numbers as positive, no matter whether they are truly positive or negative ? I am having to cast each column to varchar to find out if there are any...
5
by: Subrahmanyam Arya | last post by:
Hi Folks , I am trying to solve the problem of reading the numbers correctly from a serial line into an intel pentium processor machine . I am reading 1 byte and 2byte data both positive...
15
by: jaks.maths | last post by:
How to convert negative integer to hexadecimal or octal number? Ex: -568 What is the equivalent hexadecimal and octal number??
11
by: drtimhill | last post by:
I'm just starting out on Python, and am stumped by what appears an oddity in the way negative indices are handled. For example, to get the last character in a string, I can enter "x". To get the...
39
by: Frederick Gotham | last post by:
I have a general idea about how negative number systems work, but I'd appreciate some clarification if anyone would be willing to help me. Let's assume we're working with an 8-Bit signed integer,...
3
by: Steven D'Aprano | last post by:
Problem: I have an application where I need to print integers differently depending on whether they are positive or negative. To be more specific, I have to print something that looks like: ...
15
by: Ivan Novick | last post by:
Hi, Is it possible to have negative integer literal or only positive? As far as I understand, the code below would be a positive integer literal and the unary negative operator. x = -3.2; ...
19
by: Johs | last post by:
I need to make some special action if 'a' and 'b' are both positive or both negative. Is there some inbuilt function to check this? Johs
10
by: johnewing | last post by:
I am trying to figure out how to test if two numbers are of the same sign (both positive or both negative). I have tried abs(x) / x == abs(y) / y but that fails when one of the numbers is 0. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.