Here’s the problem.
I ,for example,have a string “2500”.Its converted from byte array into string.I have to convert it to decimal(int).
This is what I should get:
string : "2500"
byte[] : {0x25, 0x00}
UInt16 : 0x0025 //note its reversed
int : 43 //decimal of 0x0025
How do I do that?
Converting from hex string to UInt16 is
UInt16.Parse(s, NumberStyles.AllowHexSpecifier).You’ll need to write some code to do the “reversal in two-digit blocks” though. If you have control over the code that generates the string from the byte array, a convenient way to do this would be to build the string in reverse, e.g. by traversing the array from length – 1 down to 0 instead of in the normal upward direction. Alternatively, assuming that you know it’s exactly a 4 character string,
s = s.Substring(2, 2) + s.Substring(0, 2)would do the trick.