I’m trying to use the MiscUtil.Conversion utility in Silverlight.
http://www.yoda.arachsys.com/csharp/miscutil/
When I try to compile it, I get an error saying Silverlight’s BitConverter class does not have these two methods:
DoubleToInt64Bits
Int64BitsToDouble
Well, I opened up Reflector and found them in mscorlib:
public unsafe long DoubleToInt64Bits(double value)
{
return *(((long*)&value));
}
public unsafe double Int64BitsToDouble(long value)
{
return *(((double*) &value));
}
But the problem with that is that Silverlight does not allow unsafe code. In the project properties menu there’s a empty checkbox next to “allow unsafe code”, but you cannot change the value.
How can I do this in Silverlight?
Have a look at
BitConverter.ToDouble(byte[], int)andBitConverter.GetBytes(double). If they exist in Silverlight, they may well be good enough. I’m going to investigate this for Protocol Buffers anyway – if I find a good solution, I’ll port it back to MiscUtil.