Mar-23-2022, 01:51 PM
Hello,
I have a function that take bits and cut them according to my needs
so it's other way around
for example
if I take "CA"
in bits its - 1100 1010
I want to cut only bits 2-4
but I need to enter numbers 4-7
then I thought to use dictionary - but then it's went wrong
I need to change the order - (end - start) , and it also change the order of the bits
01 - change to 10
is there other way to do it? without overthinking what need to be cut?
Thanks,
I have a function that take bits and cut them according to my needs
BITS_ORDER_CHANGE = {8: 0, 7: 1, 6: 2, 5: 3, 4: 4, 3: 5, 2: 6, 1: 7} def GetBits(Byte, start, end): # bits order 8765 4321 , str order 0123 4567 Final_calculation = round((int(Byte, 16) * 1 + 0), 0) bits = "{0:b}".format(Final_calculation) Full_bits = bits.zfill(8) print('old start', start) start = BITS_ORDER_CHANGE[start] print('new start', start) print('old end', end) end = BITS_ORDER_CHANGE[end] print('new end', end) Wanted_bits = Full_bits[end:start] return Wanted_bitsmy problem is that when I cut it I think is string mode , whie the bits are is in bits mode
so it's other way around
for example
if I take "CA"
in bits its - 1100 1010
I want to cut only bits 2-4
but I need to enter numbers 4-7
then I thought to use dictionary - but then it's went wrong
I need to change the order - (end - start) , and it also change the order of the bits
01 - change to 10
is there other way to do it? without overthinking what need to be cut?
Thanks,