浮点数与十六进制数如何互相转换.
浮点数与十六进制数如何互相转换.
------解决方案--------------------float f = 123.456;
string s = BitConverter.ToString(BitConverter.GetBytes(f)).Replace( "- ", " ");
------解决方案--------------------//贴到这个份上,无语
float f = 1.2f;
string s = BitConverter.ToString(BitConverter.GetBytes(f)).Replace( "- ", " ");
//s = s.Replace( " ", " ");//如果中间有空格
byte[] arr = new byte[s.Length / 2];
for (int i = 0; i < s.Length / 2; i++)
arr[i] = Convert.ToByte(s.Substring(i * 2, 2), 16);
float f1 = BitConverter.ToSingle(arr, 0);
Text = f1.ToString();