How to convert hexadecimal word to signed integer in python 2-7? -
i trying write method converting hexadecimal words signed integers. want utilize python 2-7. in python3 can following
def word2int(hex_str): ba = bytes.fromhex(hex_str) homecoming int.from_bytes(ba,byteorder='big',signed=true)
however, neither of these methods (i.e. fromhex , from_bytes) defined in python 2-7. there nice , simple methods of doing in python 2-7?
use int
convert unsigned integer, , manually convert signed.
def word_to_int(hex_str): value = int(hex_str, 16) if value > 127: value = value-256 homecoming value
python-2.7 python-3.x
No comments:
Post a Comment