On Sun, 4 Jan 2004 16:50:16 -0000, Jon Skeet [C# MVP]
<sk***@pobox.com> wrote:
Nadav <No*@today.com> wrote: How can a UInt64 be converted to a byte[] ????
See BitConverter.GetBytes(ulong).
And if speed is a factor:
unsafe static byte[] GetBytes(UInt64 value)
{
byte[] bytes = new byte[8];
fixed(byte* b = bytes)
*((UInt64*)b) = value;
return bytes;
}
The BitConverter version has a couple layers of indirection, so its
about 3 times slower (GetBytes(value)>GetUInt64Bytes(value)>internal
runtime call). It's strange, they sometimes do internal calls (for
Integral types) and sometimes they write their own (for floating-point
types).
Austin