1
0
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:
Oliver Booth 2022-04-28 22:44:01 +01:00
parent ef9c186684
commit 4f3dd908c6
No known key found for this signature in database
GPG Key ID: 32A00B35503AF634
2 changed files with 8 additions and 10 deletions

View File

@ -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>

View File

@ -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;
}
}
}