int.Parse() returning hexa ...

  • Thread starter Thread starter Raj
  • Start date Start date
R

Raj

Why is int.Parse(), Int16, Int32, Short Parse() returns hexa. value instead
of decimal?

For example: int.Parse("0") returns 0x0000 whereas float.Parse("0") returns
0.0

What&where's the problem?

Thank you

Regards
Raj
 
Hi Raj,

Raj said:
Why is int.Parse(), Int16, Int32, Short Parse() returns hexa. value
instead
of decimal?
For example: int.Parse("0") returns 0x0000 whereas float.Parse("0")
returns
0.0

The return value is something that can be displayed in different ways. What
you describe is the format when you display a value and that is something
that you can choose freely. So the internal stored value od Zero must be
transformed into a string that you can print. You can check the method
"ToString" (e.g. http://msdn.microsoft.com/en-us/library/cht2hdff.aspx) for
more details. (There you find a lot of information. So it is not only a
question to display it as hex or decimal. The culture is also important.
There are a lot of ways to display a number e.g. - 1.234.567 - 1,234,567,
(1.234.567), ...

Hope I was able to help a little.

With kind regards,

Konrad
 
Raj said:
Why is int.Parse(), Int16, Int32, Short Parse() returns hexa. value instead
of decimal?

Hexadecimal is a _text_ format. It only even makes sense to talk about
hexadecimal in the context of a string. On the other hand, the Parse()
method for Int32, Int16, Single, etc. returns a _numeric_ value. It is
not possible for the latter to have the former characteristic. They are
completely different.
For example: int.Parse("0") returns 0x0000 whereas float.Parse("0") returns
0.0

What&where's the problem?

Surely your interpretation. :)

It's not possible to pinpoint where you've misunderstood since you
haven't elaborated on how you're examining the result of the Parse()
methods. But for sure, you must be using some mechanism to examine the
result of the Parse() method that is specifically designed and/or
configured to display the text representation of the parsed value as
hexadecimal.

Pete
 
Raj said:
Why is int.Parse(), Int16, Int32, Short Parse() returns hexa. value instead
of decimal?

They don't.
For example: int.Parse("0") returns 0x0000 whereas float.Parse("0") returns
0.0

int.Parse("0") returns an integer that is zero and float.Parse("0")
returns a float that is zero.
What&where's the problem?

The problem is that you confuse the value with it's textual
representation. A number doesn't have a base, thus is neither
hexadecimal not decimal, it's just the value. It's when you create the
textual representation of the number that you use a base.

If you are looking in the debug view to find out what the value is, you
have enabled the "Hexadecimal Display" option. You can right click and
disable this if you want decimal display instead.
 
Back
Top