python - Working with bit streams -
I have base 64 encoded bit stream, I want to work with it. After decoding it, I get a byte object (pie 3k bitd) with base64.b64decode
, which has a decode code. The problem is now, that I want to work on that byte, objects with bit-wise operation, such as transfer, bit wise and
etc., but this is not possible because it is a byte sequence. / P>
Is there a way to binary action on that decode code?
Try to use
list (biotech)
example.
& gt; & Gt; & Gt; Bstring = b "Hello World" & gt; & Gt; & Gt; List (bostring) [72, 101, 108, 108, 111, 32, 87, 111, 114, 108, 100] & gt; & Gt; & Gt;
If you want a huge bitfile instead of all those octets
& gt; & Gt; & Gt; Less than Funktal import & gt; & Gt; & Gt; Less (Lambda X, Y: (x & lt; & lt; 8) + y, list (b "Hello world") 87521618088882533792115812 & gt; & Gt; & Gt; Bin (_) '0b100100001100101011011000110110001101111001000000101011101101111011100100110110001100100' & gt; & Gt; & Gt;
You did not say how you are counting bits, maybe they have reversed
& gt; & Gt; & Gt; Less (Lambda X, Y: (x & lt; & lt; 8) + y, list (b "Hello world" [:: - 1]) 121404708493354166158910792 >>> >>> BITS = BIN (_) [2:]
and even byte pad bytes
> gt; bit = bits.zuffill ((((( Beats -1)) / 8 + 1) * 8) Bits '0110010001101100011100100110111101010111001000000110111101101100011011000110010101001000'
Change the first 6 bits to an integer
< Pre> & gt; & gt; Int (bit [: 6], 2) 25
and then the following 4 bits
& Gt; & gt; int (bits [6:10], 2) 1
Comments
Post a Comment