I have this: struct.pack('I', 0b10101010101100101010001000001000).encode('base64')
which is good for converting 32 bits to base 64… but is there an easy way to convert any number of bits to base 64?
like, anywhere between 128 and 512?
EDIT:
where I’m at:
My original command:
>>> struct.pack('I', 0b10101010101100101010001000001000).encode('base64')
'CKKyqg==\n'
One of the suggestions is to use \x for hex and convert that… so far so good.
>>> struct.pack('I', 0b10101010101100101010001000001000).encode('hex')
'08a2b2aa'
>>> '\x08\xa2\xb2\xaa'.encode('base64')
'CKKyqg==\n'
but can I do the samething with binary?
>>> '\b10101010\b10110010\b10100010\b00001000'.encode('base64')
'CDEwMTAxMDEwCDEwMTEwMDEwCDEwMTAwMDEwCDAwMDAxMDAw\n'
nope =(
If you have an arbitrary-long binary string, use string hex escapes:
So your example would be: