Python Forum
enter string into list according to a known rule
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
enter string into list according to a known rule
#11
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
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,
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Python rule about the space character surrounding the equal sign ineuw 10 1,614 Sep-21-2023, 09:17 AM
Last Post: ineuw
  Pythone module for dynamic rule execution hemal07yc 1 8,973 Sep-13-2019, 11:25 AM
Last Post: luoheng
  I converted string to 'list', but it doesn't look like a list! mrapple2020 3 3,239 Apr-07-2019, 02:34 PM
Last Post: mrapple2020
  Create Alert if string from list appears on other list javalava 1 2,504 Sep-17-2018, 02:44 PM
Last Post: DeaD_EyE
  List of pathlib.Paths Not Ordered As Same List of Same String Filenames QbLearningPython 20 15,335 Nov-16-2017, 04:47 PM
Last Post: QbLearningPython
  Create a new list by comparing values in a list and string DBS 2 3,520 Jan-14-2017, 07:59 AM
Last Post: Yoriz

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020