hexathon

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

commit 45ffe6e016056478df3e105f6c75f66b6c4c6016
parent 6324c58e428a60b8bd4619ee2a53dd8f94d1749d
Author: lash <dev@holbrook.no>
Date:   Mon, 21 Feb 2022 09:13:27 +0000

Add to_int method

Diffstat:
MCHANGELOG | 4++++
Mhexathon/parse.py | 13+++++++++++++
Msetup.cfg | 2+-
3 files changed, 18 insertions(+), 1 deletion(-)

diff --git a/CHANGELOG b/CHANGELOG @@ -1,2 +1,6 @@ +- 0.1.4 + * Add to_int method +- 0.1.3 + * Fix missing 0x strip in compact handling - 0.0.1 * Add valid, uniform, 0x strip and add diff --git a/hexathon/parse.py b/hexathon/parse.py @@ -82,3 +82,16 @@ def int_to_minbytes(v, byteorder='big'): def int_to_minhex(v): return int_to_minbytes(v).hex() + + +def to_int(v, need_prefix=False): + if len(v) == 0: + raise ValueError('empty value') + if need_prefix: + if len(v) < 2: + raise ValueError('value too short') + if v[:2] != '0x': + raise ValueError('missing prefix') + + v = strip_0x(v) + return int(v, 16) diff --git a/setup.cfg b/setup.cfg @@ -5,6 +5,6 @@ url=https://gitlab.com/nolash/python-hexathon author_email=dev@holbrook.no name=hexathon -version=0.1.3 +version=0.1.4 description=Common and uncommon hex string operations author=Louis Holbrook