Search code examples
pythonhexconcatenation

How to concatenate two arbitrary long hex values?


I have two variables. Variable A contains 1024 bytes (not always ascii characters, arbitrary hex values) Variable B contains 64 bytes (not always ascii characters, arbitrary hex values)

How can I generate a variable C such that C = A || B ? (|| means concatenation)


Solution

  • The + operator works on bytes too:

    >>> b'\x12\x14' + b'\x16\x0b'
    b'\x12\x14\x16\x0b'