如何将浮点数转换为十六进制 [英] How to convert float to hexadecimal

查看:1103
本文介绍了如何将浮点数转换为十六进制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

朋友们,
我需要在C#3.0中将Float转换为十六进制,示例输入为5.5表示,输出应为40B0. 非常紧急 否.

请帮帮我..

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..

推荐答案

转换为十六进制字符串
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);


只需使用正确的格式字符串(十六进制)打印您的值如此处所述的输出 [
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.


这篇关于如何将浮点数转换为十六进制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆