12,449,905 members (40,792 online)
Rate this:
See more:
Hi friends,
I need to convert Float to hexadecimal in C# 3.0 Example input is 5.5 means, output should be 40B0. Very urgent No.

Posted 15-Nov-10 2:51am
Updated 15-Nov-10 8:39am
v2
ARopo 16-Nov-10 4:59am

Some people seem to have a problem with your statement of urgentcy. People will answer your query as fast as possible adding urgent does seem to get a lot of people's backs up which is a shame because it is quite an interesting question.

Rate this:

## Solution 2

To convert to a hex string
```double dbVal = 5.5;
long lVal = BitConverter.DoubleToInt64Bits(dbVal);
string hex = lVal.ToString("X");
```

To convert it back

```long lval2 = Convert.ToInt64(hex, 16);
double dbVal2 = BitConverter.Int64BitsToDouble(lval2);```
v4
Rate this:

## Solution 1

Just print your value with the correct format string for hex output as described here[^].

BTW I note that this was not urgent enough for you to find the MSDN reference.
v2

Top Experts
Last 24hrsThis month
 OriginalGriff 305 Maciej Los 133 Karthik Bangalore 130 David_Wimbley 110 ppolymorphe 104
 OriginalGriff 5,988 Karthik Bangalore 3,465 ppolymorphe 3,406 Maciej Los 3,005 Richard Deeming 2,775