1. Anuncie Aqui ! Entre em contato fdantas@4each.com.br

[Python] Why hexa decode need two digit

Discussão em 'Python' iniciado por Stack, Outubro 8, 2024.

  1. Stack

    Stack Membro Participativo

    The hex Python function produce 0x0 for the 0 number:

    >>> hex(0)
    '0x0'


    But bytes.fromhexa only accept hexa with minimum of two digits:

    >>> bytes.fromhex(hex(0)[2:])
    Traceback (most recent call last):
    File "<stdin>", line 1, in <module>
    ValueError: non-hexadecimal number found in fromhex() arg at position 1
    >>> bytes.fromhex('00')
    b'\x00'


    Why bytes.fromhexa accept hexa from two digits and no with one digit ?

    Continue reading...

Compartilhe esta Página