mirror of
https://github.com/oliverbooth/X10D
synced 2024-11-09 23:25:43 +00:00
Remove evil hack for 8-bit pack/unpack
This commit is contained in:
parent
ef9c186684
commit
4f3dd908c6
@ -25,13 +25,14 @@ public static class BoolListExtensions
|
||||
throw new ArgumentException("Source cannot contain more than than 8 elements.", nameof(source));
|
||||
}
|
||||
|
||||
unsafe
|
||||
byte result = 0;
|
||||
|
||||
for (var i = 0; i < source.Count; i++)
|
||||
{
|
||||
fixed (bool* p = source.ToArray())
|
||||
{
|
||||
return (byte)(*(ulong*)p * 72624976668147840L >> 56); // evil fucking bit hack
|
||||
}
|
||||
result |= (byte)(source[i] ? 1 << i : 0);
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
|
@ -33,12 +33,9 @@ public static class ByteExtensions
|
||||
throw new ArgumentException($"Destination must be at least {Size} in length.", nameof(destination));
|
||||
}
|
||||
|
||||
unsafe
|
||||
for (var index = 0; index < Size; index++)
|
||||
{
|
||||
fixed (bool* p = destination)
|
||||
{
|
||||
*(ulong*)p = ((ulong)value * 567382630219905) & 72340172838076673UL; // evil fucking bit hack
|
||||
}
|
||||
destination[index] = (value & (1 << index)) != 0;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user