0

I have a string varaible str. This variable has a value "26". Can I convert it into hex that results 0x26 not 0x1A.

Means str="26"

int iConvert=**SomeConvertionFunction(str)**

should result into iConvert=0x26

user2861226
  • 169
  • 13

2 Answers2

3
int hex = int.Parse("26", NumberStyles.HexNumber);

hex value will be 38 which is the decimal representation of hex number 0x26.

Sriram Sakthivel
  • 72,067
  • 7
  • 111
  • 189
0

If I understand your question basically you want to store the Hex value of the string in a int?

having the value 26 or 0x1A is the same.

To convert the int to a string use int.ToString('X');

And please not that 26 in base 10 in equal to 0x1A in base 16.

MaxVerro
  • 96
  • 1
  • 9