y hold integer values, you just choose to use 0b binary literals
to define them. If you want to combine the two into z, you can
easily do so using a shifting operation and binary bitwise
operations: >>> x = 0b00010101010 >>> y = 0b1110000 >>> z = (x
<< 7) | y Do note that python does not track how many bits
'precision' you want to keep on such values; you defined y with
7 bits of information, so I had to shift x to the left 7 times
to make room for y. You'd have to track this information
yourself. Your next problem is representing data as base64 as
this format requires you to provide it with bytes only. That's
chunks of 8 bits of binary data. This means you'll have to align
your bits to the 8-bit boundaries and then turn these into bytes
(e.g. strings). You won't be able to get around that, I'm
afraid. I'd use the struct module for that, it lets you pack
integers and other data-types into bytes with ease: >>> import
struct >>> struct.pack('>H', x) >>> struct.pack('>H',
x).encode('base64') In the above example