I have an integer that is 8 bits and I want to distribute these bits into beginnings of 4 integers (4x8 bit) two by two. For example:
bit_8 = 0b_10_11_00_11
bit_32 = b"\x12\x32\x23\54" # --> [0b100_10, 0b1100_10, 0b1000_11, 0b1011_00]
what_i_want = [0b100_10, 0b1100_11, 0b1000_00, 0b1011_11]
For readability I wrote numbers in a list, but I want them as bytes
. I am not very good at bit manipulations and I couldn't find a good way.
I will repeat this process many times, so I need a fast solution. I found a way of setting bits by one by at here, but I wonder if there is a better way for my problem.
Language is not so important, I need an algorithm. Nevertheless I prefer Python.