Convert Hex strings 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. Regards, Chua Wen Ching Visit us at http://www.necoders.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. Regards, Chua Wen Ching Visit us at http://www.necoders.com
You need to manually loop through your Hex string, a byte at a time and convert it to decimal. Like this
byte []hexValues = new byte[text.Length /3 + 1];
int index = 0;
for (int i = 0; iRegards
Senthil
_____________________________
My Blog | My Articles | WinMacro