Hi Group
I am trying to write a method to unpack a byte array into an Uint64.
But the results are wrong.
public static void UnpackUint64(ref UInt64 dst, byte[] Data,
ref uint Index)
{
dst = Data[Index++];
dst += (UInt64)((Data[Index++] & 0xffffffff) << 08);
dst += (UInt64)((Data[Index++] & 0xffffffff) << 16);
dst += (UInt64)((Data[Index++] & 0xffffffff) << 24);
dst += (UInt64)((Data[Index++] & 0xffffffff) << 32);
dst += (UInt64)((Data[Index++] & 0xffffffff) << 40);
dst += (UInt64)((Data[Index++] & 0xffffffff) << 48);
dst += (UInt64)((Data[Index++] & 0xffffffff) << 56);
}
The method I use to pack the Uint64 into the byte array is
public static void PackUint64(ulong src, byte[] Data, ref uint
Index)
{
Data[Index++] = (byte)(src & 0xff);
Data[Index++] = (byte)((src >08) & 0xff);
Data[Index++] = (byte)((src >16) & 0xff);
Data[Index++] = (byte)((src >24) & 0xff);
Data[Index++] = (byte)((src >32) & 0xff);
Data[Index++] = (byte)((src >40) & 0xff);
Data[Index++] = (byte)((src >48) & 0xff);
Data[Index++] = (byte)((src >56) & 0xff);
}
The Pack looks okay, but I have spent hours on the UnPack and I just
seem to be confusing myself.
Can anyone tell me what is wrong with my unpack method?
Thanks
Stuart