求这两个算法
Float.floatToRawIntBits(paramFloat)
Double.doubleToRawLongBits(paramDouble)这个是反的,
private float intBitsToFloat(int bits)
{
int s = ((bits >> 31) == 0) ? 1 : -1;
int e = ((bits >> 23) & 0xff);
int m = (e == 0) ?
(bits & 0x7fffff) << 1 :
(bits & 0x7fffff) | 0x800000; return (float)(s * m * Math.Pow(2, e - 150));
} private double longBitsToDouble(long bits)
{
int s = ((bits >> 63) == 0) ? 1 : -1;
int e = (int)((bits >> 52) & 0x7ffL);
long m = (e == 0) ?
(bits & 0xfffffffffffffL) << 1 :
(bits & 0xfffffffffffffL) | 0x10000000000000L; return (s * m * Math.Pow(2, e - 1075));
}
Float.floatToRawIntBits(paramFloat)
Double.doubleToRawLongBits(paramDouble)这个是反的,
private float intBitsToFloat(int bits)
{
int s = ((bits >> 31) == 0) ? 1 : -1;
int e = ((bits >> 23) & 0xff);
int m = (e == 0) ?
(bits & 0x7fffff) << 1 :
(bits & 0x7fffff) | 0x800000; return (float)(s * m * Math.Pow(2, e - 150));
} private double longBitsToDouble(long bits)
{
int s = ((bits >> 63) == 0) ? 1 : -1;
int e = (int)((bits >> 52) & 0x7ffL);
long m = (e == 0) ?
(bits & 0xfffffffffffffL) << 1 :
(bits & 0xfffffffffffffL) | 0x10000000000000L; return (s * m * Math.Pow(2, e - 1075));
}
解决方案 »
- 有这样的一个问题,求指教!
- 求一种技术
- C# treeView 获取被选中节点问题
- C#: 如何从date time picker控件取出年月日不带时间格式的值?注意要的值得是日期型的,字符串的我也会。
- 关于从xml导入的dataset中放入数据库中的问题
- 关于windows服务的几个疑问,大家帮帮忙,解决立刻给分!!
- 图片等比缩放,像素质量不高
- 调用api函数,string类型,为什么不能替代byte[]?
- 要跟朋友合資開公司了,各位給我點建議(5貼500分相送)
- 为何SqlCommand总是不能返回SqlDataReader???
- asp.net服务器控件添加事件点击按钮位置变了
- C# winform窗体可见性控制,请给予指点
using System.Collections.Generic;
using System.Linq;
using System.Text;namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
float[] input = { 1277.995f, 219.7558f, 1004.7796f };
uint[] convtoint = input.Select(x => ftol(x)).ToArray();
foreach (var item in convtoint)
{
Console.WriteLine(item);
}
Console.WriteLine("---------");
var convback = convtoint.Select(x => ltof(x));
foreach (var item in convback)
{
Console.WriteLine(item);
}
} private static float ltof(uint x)
{
byte[] b = BitConverter.GetBytes(x);
return BitConverter.ToSingle(b, 0);
} static uint ftol(float f)
{
byte[] r = BitConverter.GetBytes(f);
return (uint)(r[3] * 16777216 + r[2] * 65536 + r[1] * 256 + r[0]);
}
}
}
1151320023
1130086780
1148924389
---------
1277.995
219.7558
1004.78
Press any key to continue . . .
static uint ftol(float f)
{
byte[] r = BitConverter.GetBytes(f);
return BitConverter.ToUInt32(r, 0);
}