Click here to Skip to main content
13,055,861 members (55,651 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Hi All,
Bit of a question, bit of a method of ordering thoughts I am reading back a hex value from a device it comes in an odd format for values 0-15, 0 to A I can parse it fine with no problems using:
intCredit_Value_Reverse = int.Parse(txtValueCredit.Text, System.Globalization.NumberStyles.HexNumber);

that is when the string is reversed. I believe my method for reversing is causing the problems I see now when the number I should get is 25 it returns 19000000
19 00 00 00
87 65 43 21
need to be displayed as
00 00 00 19 or bit pattern
21 43 65 87
to give 25 I have used a string builder to reverse the pattern which worked with 0-15 as only the string was A0000000 to give 0000000A. I am thinking along the following lines at the moment
    private void button1_Click(object sender, EventArgs e)
            int a = 0;
           // int Number_val = 0;
            string[] Credit_Value_Correct = new string[5];
          //  string Trimmed = null;
            for (int i = 0; i <= value_split.Length; i += 2)
                if (i == value_split.Length)
             //   MessageBox.Show(value_split.Substring(i, 2));
                Credit_Value_Correct[a] += value_split.Substring(i, 2);
                // Number_val = Convert.ToInt16(value_split.Substring(i, 2));
             //   if (!(Number_val % 0 == 0))
             //   {
              //  }
          //  MessageBox.Show(value_split);
            //for (int j = 0; j <= 3; j++)
            //  //  MessageBox.Show("Credit_Value_Correct[" + j.ToString() + "] = " + Credit_Value_Correct[j]);
            textBox1.Text = Credit_Value_Correct[3] + Credit_Value_Correct[2] + Credit_Value_Correct[1] + Credit_Value_Correct[0];

This would appear to split the number into two bit data chunks and displays them in the right order (so 25 appears as 19!) I think I can then do the conversion need with
int myInt = int.Parse(textBox1.Text, System.Globalization.NumberStyles.HexNumber);

This question is related to yesterdays "Is There An Easy Way of Getting Values From This String" I will give some of those response a go after lunch, thanks this has helped get ducks in a line.

Posted 24-Jan-13 1:59am
Edo Tzumer 24-Jan-13 8:28am
What's the question?
glennPattonWork 24-Jan-13 8:35am
Sorry, thinking while typing makes it less painful at times!
sjelen 24-Jan-13 12:16pm
What is painful, thinking or typing? ;)
glennPattonWork 24-Jan-13 12:21pm
A little of both at the moment I managed to burn on finger tip yesterday!

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

I am not sure if I understand your question. Nevertheless, I will attempt an answer.

You can convert a Hexadecimal string to an Integer using the following:
Dim intValue As Integer = Convert.ToInt32(strYourHexValue, 16)

If strYourHexValue contains "00000019", intValue will contain 25.


Example to study and learn from:
string strInput = "19000000";
// "78563412"
string strOutput = "";
int intOutput = 0;
int x = 0;
// Ensure an even number of digits
if (strInput.Length % 2 != 0) {
	Interaction.MsgBox("Input string must be an even number of hexadecimal characters");
// Reverse hex characters
for (x = strInput.Length - 2; x >= 0; x += -2) {
	strOutput += strInput.Substring(x, 2);
// Convert to integer
try {
	// Use Try block in case strInput did not contain Hexadecimal characters
	intOutput = Convert.ToInt32(strOutput, 16);
} catch (Exception ex) {
Interaction.MsgBox(strOutput + "=" + intOutput.ToString());
glennPattonWork 24-Jan-13 8:34am
Thanks, sorry for the question being a bit hard to understand it is just that I was thinking while typing, the string appears as 1900000 I need to reverse it so it appears as 000019 rather than a straight reverse which I did yesterday.
Mike Meinz 24-Jan-13 9:08am
See the example I added to Solution 1.
glennPattonWork 24-Jan-13 10:44am
Sorry for that, but looking at it you gave VB to answer a C# question, here starts a holy war! Thanks got the problem sorted!
glennPattonWork 24-Jan-13 10:44am
Thanks to all I think I have solved it?
Mike Meinz 24-Jan-13 10:52am
I changed the example to C# for you.

I used Free Converter Tool on the Developer Fusion web site.
glennPattonWork 24-Jan-13 11:32am
Oh thanks for that link and sorry I wasted your time!
Mike Meinz 24-Jan-13 11:43am
Not a waste. An opportunity for a teaching moment!

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

  Print Answers RSS
Top Experts
Last 24hrsThis month

Advertise | Privacy | Mobile
Web02 | 2.8.170713.1 | Last Updated 24 Jan 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100