hexathon

Common and uncommon hex string operations for python3
git clone git://git.defalsify.org/python-hexathon.git
Log | Files | Refs | LICENSE

commit d333e14a63fe5744a31b7cef6ed4119aebe54acd
parent 16741c6c6206b0e5673076896c38258bc6232983
Author: nolash <dev@holbrook.no>
Date:   Sat, 27 Mar 2021 15:42:47 +0100

Add int to minimal byte size parser

Diffstat:
Mhexathon/parse.py | 14++++++++++++++
Msetup.cfg | 2+-
2 files changed, 15 insertions(+), 1 deletion(-)

diff --git a/hexathon/parse.py b/hexathon/parse.py @@ -56,3 +56,17 @@ def pad(hx, byte_length): hx = strip_0x(hx) hx = hx.rjust(byte_length * 2, '0') return hx + + +def int_to_minbytes(v, byteorder='big'): +# c = 0x100 +# i = 1 +# while c <= v: +# i += 1 +# c = c << 8 + l = ((v.bit_length() - 1) >> 3) + 1 + return v.to_bytes(l, byteorder=byteorder) + + +def int_to_minhex(v): + return int_to_minbytes(v).hex() diff --git a/setup.cfg b/setup.cfg @@ -1,6 +1,6 @@ [metadata] name = hexathon -version = 0.0.1a6 +version = 0.0.1a7 description = Common and uncommon hex string operations author = Louis Holbrook author_email = dev@holbrook.no