From 95b769f1656f76b1294e968b4d92ad90137bd82c Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Fri, 28 Jun 2024 12:42:29 -0400 Subject: [PATCH] Rewrite to_rugbits --- thesethreewords.py | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/thesethreewords.py b/thesethreewords.py index 357423d..b3d8c2d 100644 --- a/thesethreewords.py +++ b/thesethreewords.py @@ -165,7 +165,7 @@ class WordHasher(object): return N - def to_rugbits(self, integer): + def to_rugbits_old(self, integer): """Convert a 45bit `integer` to a list of 3rugbits A rugbit is like a byte but with 15bits instead of eight. @@ -176,6 +176,17 @@ class WordHasher(object): integer & fifteen_bits] return rugbits + def to_rugbits(self, integer): + """Convert a 45bit `integer` to a list of 3rugbits + + A rugbit is like a byte but with 15bits instead of eight. + """ + fifteen_bits = 0b111111111111111 + rugbits = [(integer >> 30) & fifteen_bits, + (integer >> 15) & fifteen_bits, + integer & fifteen_bits] + return rugbits + def rugbits_to_int(self, rugbits): """Convert a list of `rugbits` to an integer""" assert len(rugbits) == 3