Click here to Skip to main content
15,886,199 members
Please Sign up or sign in to vote.
2.50/5 (2 votes)
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.

Please help me out guys..
Posted
Updated 15-Nov-10 8:39am
v2
Comments
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.

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


To convert it back

C#
long lval2 = Convert.ToInt64(hex, 16);
double dbVal2 = BitConverter.Int64BitsToDouble(lval2);
 
Share this answer
 
v4
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.
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900