How to concatenate and convert hex to base 64 in Python?
Question: I'm trying to convert hex values into base 64.

I have a script that does some calculations to each value.  
I then want to convert the final values to base 64.

    
    
    import base64
    for i, v in enumerate([0x31, 0x37, 0x32, 0x2e]):
        z=i+v #adds positional index to hex value
        q=z+0x27 #adds constant 
        x=q^i # XORs with positional index
    print (x)
    

gives:

> 88  
>  94  
>  89  
>  91

I'm trying to convert these values into base 64. If I manually put them in
this form: `585e595b`, this code is working:

    
    
    >>> "585e595b".decode('hex').encode('base64')
    'WF5ZWw==\n'
    


Answer: One way to do it:

    
    
    data = [0x31, 0x37, 0x32, 0x2e]
    encoded = base64.b64encode(''.join(hex(x)[2:] for x in data))
    

