We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
There was an error while loading. Please reload this page.
1 parent ae209af commit 9485b4aCopy full SHA for 9485b4a
hazelcast/util.py
@@ -378,7 +378,13 @@ def int_from_bytes(buf):
378
if hasattr(int, "to_bytes"):
379
380
def int_to_bytes(number):
381
- # number of bytes to represent the number
+ # number of bytes to represent the number.
382
+ # For numbers that has not exactly 8n bit_length,
383
+ # adding 8 and performing integer division with 8
384
+ # let us get the correct width because
385
+ # (8n + m + 8) // 8 = n + 0 + 1 (assuming m < 8).
386
+ # For negative numbers, we add 1 to get rid of the
387
+ # effects of the leading 1 (the sign bit).
388
width = (8 + (number + (number < 0)).bit_length()) // 8
389
return number.to_bytes(length=width, byteorder="big", signed=True)
390
0 commit comments