Hex to Base64 conversion in Python

前端 未结 7 1021
一整个雨季
一整个雨季 2021-02-04 03:47

I want to convert a simple HEX string such as 10000000000002ae to Base 64.

The hex string is to be converted to bytes, and the bytes are then encoded to base64 notation,

7条回答
  •  走了就别回头了
    2021-02-04 04:08

    Python has native support for both HEX and base64 encoding:

    import base64
    
    def main():
        b16 = bytearray('10000000000002ae'.decode('hex'))
        b64 = base64.b64encode(b16)
    
        print b64
    

提交回复
热议问题