13,301,619 members (73,132 online)
Rate this:
See more:
Hi all,
When converting a string value to integer value the result return as hexadecimal format.
Ex: int output=Convert.ToInt16("1");
when watch output value in a add watch it displayed as 0x001.

and int output1 = Convert.ToInt32("1");
output1 value displayed as 0x00000001.
I don't the problem. But this problem occurs only in my system. Please reply me if u know the answer.
Posted 14-Nov-12 23:12pm
Updated 15-Nov-12 0:09am
v2

Rate this:

## Solution 1

No, it doesn't.

Integers do not have a "Hex format", or a "decimal format" - they are numbers (and are in fact always stored in binary).

The only time you use a hexadecimal format is when you are converting from a sting in hex format ro an integer, or from an integer to a string in hex format. In the first case, you would use:
`int myInteger = Int32.Parse(hexString, System.Globalization.NumberStyles.HexNumber);`

and in the second:
`string hexString = myInteger.ToString("X4");`
Rate this:

## Solution 2

The input string has to represent the number in decimal for Convert.ToInt16(String)[^] to work.
Its output is an integer. That has neither decimal nor hexadecimal format. It's just the correct value.
You can convert it into a string again to display it to the user. Use the ToString() method[^] for that.
If you want the output string to be in hexadecimal format, use
```Int16 number = 255;
string output = number.ToString("X");```

for that.

If you want to convert a string that represents a number in hexadecimal form to an integer, use
```Int16 number;
bool success = Int16.TryParse(
"0xFF",
NumberStyles.HexNumber,
CultureInfo.InvariantCulture,
out value
);```

Top Experts
Last 24hrsThis month
 OriginalGriff 240 Dave Kreskowiak 135 Richard MacCutchan 90 Jochen Arndt 75 Richard Deeming 70
 OriginalGriff 2,739 Richard MacCutchan 1,508 ppolymorphe 1,332 Jochen Arndt 1,330 Dave Kreskowiak 1,190