Skip to content

Commit

Permalink
Fix SetBits not overwriting bits properly
Browse files Browse the repository at this point in the history
Closes #123
  • Loading branch information
tom-weiland committed Dec 3, 2023
1 parent 948e184 commit 713d7b4
Showing 1 changed file with 3 additions and 4 deletions.
7 changes: 3 additions & 4 deletions RiptideNetworking/RiptideNetworking/Utils/Converter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,12 +170,11 @@ public static void SetBits(ulong bitfield, int amount, ulong[] array, int startB
int bit = startBit % BitsPerULong;
if (bit == 0)
array[pos] = bitfield | array[pos] & ~mask;
else if (bit + amount < BitsPerULong)
array[pos] |= bitfield << bit;
else
{
array[pos ] = (bitfield << bit) | (array[pos] & ~(mask << bit));
array[pos + 1] = (bitfield >> (64 - bit)) | (array[pos + 1] & ~(mask >> (64 - bit)));
array[pos] = (bitfield << bit) | (array[pos] & ~(mask << bit));
if (bit + amount >= BitsPerULong)
array[pos + 1] = (bitfield >> (64 - bit)) | (array[pos + 1] & ~(mask >> (64 - bit)));
}
}

Expand Down

0 comments on commit 713d7b4

Please sign in to comment.