From 713d7b4eb3ed3ea1e97b8c16eaa968f7942ab075 Mon Sep 17 00:00:00 2001 From: Tom Weiland Date: Sat, 2 Dec 2023 17:03:52 -0800 Subject: [PATCH] Fix SetBits not overwriting bits properly Closes #123 --- RiptideNetworking/RiptideNetworking/Utils/Converter.cs | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/RiptideNetworking/RiptideNetworking/Utils/Converter.cs b/RiptideNetworking/RiptideNetworking/Utils/Converter.cs index 268b16c3..4bfab74e 100644 --- a/RiptideNetworking/RiptideNetworking/Utils/Converter.cs +++ b/RiptideNetworking/RiptideNetworking/Utils/Converter.cs @@ -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))); } }