By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,190 Members | 1,653 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,190 IT Pros & Developers. It's quick & easy.

Convert Hex String to Long/Decimals?

P: n/a
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
Share this Question
Share on Google+
3 Replies


P: n/a
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

P: n/a
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

P: n/a
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 discussion thread is closed

Replies have been disabled for this discussion.