Aug-12-2021, 02:19 PM
yes this is what I want
because Bytes are numbers from 1-8
and in the list it's 0-7
I understand what you said about the str and list
my item was a list on 1 item ....
this was my mistake
now everything works as it should be :-)
Thank you !
another question for this code:
sometime I need to analyze only some bits from the byte (not the all byte)
I know how to converte the answer to bits using
0xF0 it's 240 Dec --> 11110000 bits
if I want to take bits 4 and 5 (which is 1 0 )
now I split the data using
what would be the easy way to make the cut according to the bits order and not the string order ?
this is what I'm doing now
Thanks,
because Bytes are numbers from 1-8
and in the list it's 0-7
I understand what you said about the str and list
my item was a list on 1 item ....
this was my mistake
now everything works as it should be :-)
Thank you !
another question for this code:
sometime I need to analyze only some bits from the byte (not the all byte)
I know how to converte the answer to bits using
Test_bits = "{0:b}".format(Test)so if I have:
0xF0 it's 240 Dec --> 11110000 bits
if I want to take bits 4 and 5 (which is 1 0 )
now I split the data using
wanted_bits = Test_bits[3:5]beacsue the string is left to right , but the bits order are right to left
what would be the easy way to make the cut according to the bits order and not the string order ?
this is what I'm doing now
def GetBits(Byte, start, end): bits = "{0:b}".format(Byte) Full_bits = bits.zfill(8) Wanted_bits = Full_bits[start:end] return Wanted_bits**the reason is to avoid confusion while writing the code
Thanks,