473,418 Members | 2,337 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,418 software developers and data experts.

Convert Hex String to Long/Decimals?

I have a problem. But on .NET 1.1

My Scenario:
Actually I will have a string of hexadecimals read from a xml file. Then
from the hexadecimals, i will add 1 value whenever i made any modifications.
But just i do not how to get started. It is like an incremental hexadecimals.

I have a string of hex.

string strHex = "0100000000FF";

I want to convert this Hex to decimals, just like the windows calculate,
when you type FF in Hex and click on Dec radio button, it will change to 255.

I tried string.Format("{0:d}", strHex);

I tried Convert.ToDecimal or Convert.ToInt64

But i still cannot find a solution?

----

I know how to convert long to hex. Like this.
for (long x = 000000000000; x <= 281474976710655; x++)

{

Console.WriteLine(string.Format("{0:x12}", x));

Console.ReadLine();

}

But i do not know how to do the opposite? Anyone can help me please?

Thanks.
Nov 17 '05 #1
3 14492
Hi,

you could use this:
int number;
string strHex = "0100000000FF";
number = Convert.ToInt32("FF", 16);
// ..... some operation maybe
// number++
strHex = number.ToString("X");

This works, but it doesn't output leading zeros.

Christof

"Chua Wen Ching" <Chua Wen Ch***@discussions.microsoft.com> schrieb im
Newsbeitrag news:3A**********************************@microsof t.com...
I have a problem. But on .NET 1.1

My Scenario:
Actually I will have a string of hexadecimals read from a xml file. Then
from the hexadecimals, i will add 1 value whenever i made any
modifications.
But just i do not how to get started. It is like an incremental
hexadecimals.

I have a string of hex.

string strHex = "0100000000FF";

I want to convert this Hex to decimals, just like the windows calculate,
when you type FF in Hex and click on Dec radio button, it will change to
255.

I tried string.Format("{0:d}", strHex);

I tried Convert.ToDecimal or Convert.ToInt64

But i still cannot find a solution?

----

I know how to convert long to hex. Like this.
for (long x = 000000000000; x <= 281474976710655; x++)

{

Console.WriteLine(string.Format("{0:x12}", x));

Console.ReadLine();

}

But i do not know how to do the opposite? Anyone can help me please?

Thanks.

Nov 17 '05 #2
Try the following:

Int64.Parse("0100000000FF",System.Globalization.Nu mberStyles.HexNumber)

"Chua Wen Ching" wrote:
I have a problem. But on .NET 1.1

My Scenario:
Actually I will have a string of hexadecimals read from a xml file. Then
from the hexadecimals, i will add 1 value whenever i made any modifications.
But just i do not how to get started. It is like an incremental hexadecimals.

I have a string of hex.

string strHex = "0100000000FF";

I want to convert this Hex to decimals, just like the windows calculate,
when you type FF in Hex and click on Dec radio button, it will change to 255.

I tried string.Format("{0:d}", strHex);

I tried Convert.ToDecimal or Convert.ToInt64

But i still cannot find a solution?

----

I know how to convert long to hex. Like this.
for (long x = 000000000000; x <= 281474976710655; x++)

{

Console.WriteLine(string.Format("{0:x12}", x));

Console.ReadLine();

}

But i do not know how to do the opposite? Anyone can help me please?

Thanks.

Nov 17 '05 #3
Ooops
you should use long instead of int and ToInt64 instead of ToInt32.
otherwise your string value is to big.
My Example would work up to "7FFFFFFF"

Christof

"Christof Nordiek" <cn@nospam.de> schrieb im Newsbeitrag
news:OY**************@TK2MSFTNGP14.phx.gbl...
Hi,

you could use this:
int number;
string strHex = "0100000000FF";
number = Convert.ToInt32("FF", 16);
// ..... some operation maybe
// number++
strHex = number.ToString("X");

This works, but it doesn't output leading zeros.

Christof

"Chua Wen Ching" <Chua Wen Ch***@discussions.microsoft.com> schrieb im
Newsbeitrag news:3A**********************************@microsof t.com...
I have a problem. But on .NET 1.1

My Scenario:
Actually I will have a string of hexadecimals read from a xml file. Then
from the hexadecimals, i will add 1 value whenever i made any
modifications.
But just i do not how to get started. It is like an incremental
hexadecimals.

I have a string of hex.

string strHex = "0100000000FF";

I want to convert this Hex to decimals, just like the windows calculate,
when you type FF in Hex and click on Dec radio button, it will change to
255.

I tried string.Format("{0:d}", strHex);

I tried Convert.ToDecimal or Convert.ToInt64

But i still cannot find a solution?

----

I know how to convert long to hex. Like this.
for (long x = 000000000000; x <= 281474976710655; x++)

{

Console.WriteLine(string.Format("{0:x12}", x));

Console.ReadLine();

}

But i do not know how to do the opposite? Anyone can help me please?

Thanks.


Nov 17 '05 #4

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

Similar topics

4
by: Dean G | last post by:
I need to compare two values. one from a text field 'bid' and the other from a field in an sql server database 'maxbid'. The problem is the column in the database has decimal as its data type...
4
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is...
3
by: David Lozzi | last post by:
Howdy, ISSUE 1: See issue 2 below. I have a distance calculator on my site which works great. However, the users need to sort by distance, which make sense. I'm not sure how to do it other than...
1
by: Mark Hollander | last post by:
Hi All, Could you please help me convert this code so that it will run in VB.NET Thank You Mark Hollander Private Type USER_INFO Name As String
5
by: 2redline | last post by:
I am trying to write a query in access that will pull results that are in the database in a text field and convert to where I can get a average including decimals. Any Ideas? ...
4
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However...
52
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places?...
7
by: Dag Sunde | last post by:
I want to use the format-number function to output a number with a specific number of decimals, based on the content of a node... Is there any smart way to generate differnet strings based on a...
38
by: ssecorp | last post by:
char* reverse(char* str) { int length = strlen(str); char* acc; int i; for (i=0; i<=length-1; i++){ acc = str; } return acc; }
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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:
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
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,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...

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.