Bit shifting in Python
Since b_int is limited to bytes we can change your code a little to remove the formatting.

The left_shift can only have two states, if b_int &amp; 1 is 1 or 0. And so is the same as ((b_int &amp; 1) &lt;&lt; 7). (b_int &gt;&gt; 1) is as simple as it gets, and so this can stay the same.

And so I changed it to:

def shift_bits(b_int):
    return (b_int &gt;&gt; 1) | (int('{0:08b}'.format(b_int &lt;&lt; 7)[-8:], 2))

def p_shift_bits(b_int):
    return ((b_int &amp; 1) &lt;&lt; 7) | (b_int &gt;&gt; 1)


Which works as intended:

for i in range(1 &lt;&lt; 9):
    if shift_bits(i) != p_shift_bits(i):
        print(i)
        break


However, you can still speed it up if you used functools.lru_cache:

@functools.lru_cache(None)
def pc_shift_bits(b_int):
    return ((b_int &amp; 1) &lt;&lt; 7) | (b_int &gt;&gt; 1)




These gave the following timings:

&gt;&gt;&gt; timeit.timeit('shift_bits(i)', 'from __main__ import shift_bits; i=183')
1.9397294419024576
&gt;&gt;&gt; timeit.timeit('p_shift_bits(i)', 'from __main__ import p_shift_bits; i=183')
0.4003988483403518
# Yes heavily biased, but if the length of data is greater than 256, it comes into play.
&gt;&gt;&gt; timeit.timeit('pc_shift_bits(i)', 'from __main__ import pc_shift_bits; i=183')
0.15648568020111497