converting string to decimal

Abdul Hayee

Member
Joined
Mar 31, 2020
Messages
24
Programming Experience
Beginner
Dear All
I have a string which is actually a HEX representation and i want to convert it into decimal and show on textboxes. following is the string and explaination of it.

010420003C0064003C006409E207A313EC1324000000000000000000000000000000002E45
Above is the string of HEX without any space. acutally it is like that
01 04 20 00 3C 00 64 00 3C 00 64 09 E2 07 A3 13 EC 13 24 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 2E 45

01 is Hex and decimal of this is 1 (want to show this decimal no in a textbox)
04 is Hex and decimal of this is 4 (want to show this decimal no in a textbox)
20 is Hex and decimal of this is 32 (want to show this decimal no in a textbox)
so on....
Kindly guide me how to start doing this?
 
acutally it is like that
Are you sure that is a string, and not a byte array displayed to you somehow as hex values? It is a common way to display byte data that otherwise has no string representation, especially grouped like that with two chars per byte.
 
Are you sure that is a string, and not a byte array displayed to you somehow as hex values? It is a common way to display byte data that otherwise has no string representation, especially grouped like that with two chars per byte.
Actually i am coping this data from another file and paste it in the textbox. so the value i entered in a textbox is treated as a string or hex format?

1617002560895.png
 
Here's how you might convert a string of hexadecimal digits into a collection of bytes:
C#:
var str = "010420003C0064003C006409E207A313EC1324000000000000000000000000000000002E45";
var bytes = new List<byte>();

for (var i = 0; i < str.Length; i += 2)
{
    bytes.Add(Convert.ToByte(str.Substring(i, 2), 16));
}
What you then do with those bytes is completely up to you. If you want to display them in a TextBox then by all means do so, but that's not really something that you should need our help with.
 
Back
Top Bottom