diff options
author | Determinant <[email protected]> | 2018-07-27 17:30:05 -0400 |
---|---|---|
committer | Determinant <[email protected]> | 2018-07-27 17:30:05 -0400 |
commit | d2de1d9a704fc4b23e9a9fb8d610620d6d4752c1 (patch) | |
tree | ae706f99bf614470a25abc587cec87ae3fb23341 | |
parent | 473551d760bb52d3c8d12b2096c10210e9387389 (diff) |
fix bit operation bugs in Bits
-rw-r--r-- | include/salticidae/stream.h | 4 | ||||
-rw-r--r-- | test/test_stream.cpp | 4 |
2 files changed, 6 insertions, 2 deletions
diff --git a/include/salticidae/stream.h b/include/salticidae/stream.h index 267d294..50a7f70 100644 --- a/include/salticidae/stream.h +++ b/include/salticidae/stream.h @@ -360,13 +360,13 @@ class _Bits { void set(uint32_t idx) { auto i = idx >> shift_per_datum; auto pos = idx & (bit_per_datum - 1); - data[i] ^= ((data[i] >> pos) ^ 1) << pos; + data[i] ^= (((data[i] >> pos) & 1) ^ 1) << pos; } void unset(uint32_t idx) { auto i = idx >> shift_per_datum; auto pos = idx & (bit_per_datum - 1); - data[i] ^= (data[i] >> pos) << pos; + data[i] ^= ((data[i] >> pos) & 1) << pos; } void flip(uint32_t idx) { diff --git a/test/test_stream.cpp b/test/test_stream.cpp index c9fccac..7128a9a 100644 --- a/test/test_stream.cpp +++ b/test/test_stream.cpp @@ -77,5 +77,9 @@ int main() { Bits d(std::move(c)); printf("%s\n", get_hex(b).c_str()); print(b, b.size()); + Bits e(4); + e.set(0); + e.set(1); + print(e, e.size()); return 0; } |