如何从double
类型中提取字节。我知道它有 8 个字节,就像long
. 如何创建一个long
与 has 具有相同字节的变量double
。
double a = 1.5;
long b = (long)a; // <- this returns 1
// i want to get this: 0 01111111111 1000000000000000000000000000000000000000000000000000
//which is 4609434218613702656 as long (I guess :) )
请问我怎样才能快速做到这一点?
你可以这样得到
double a = 1.5;
long l = BitConverter.ToInt64(BitConverter.GetBytes(a), 0);
这将是 4609434218613702656
正如@harold 建议的那样
var l2 = BitConverter.DoubleToInt64Bits(a);
也有可能
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句