kutsurak / python-bitstring

Automatically exported from code.google.com/p/python-bitstring
0 stars 0 forks source link

Format specifier for tobyte() and tofile() #98

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
Currently these methods fill with zero bits at the end. Suggest making this the 
default but allowing alternatives:

    s.tobytes('0<')   # fill with 0, align left - the default
    s.tobytes('0>')   # fill with 0, align right
    s.tobytes('1<')   # fill with 1 bits, align left
    s.tobytes('1>')   # fill with 1s, align right

Perhaps can make both '0' and '<' the defaults (or maybe just '0') so '1' and 
'>' are also valid format specifiers.

We could also add a minimum width field:

    s.tobytes('<4')   # add zero bytes on end if needed to get to 4 bytes long
    s.tobytes('1>10') # add 1 bits to start to pad to 10 bytes long

---

This also opens the door for tohex() and tooct() methods, so maybe we should 
just have a fill() method instead:

    s.fill(8, '1>10').bytes   # same as example above
    s.fill(4)   # Pad with 0s at end to multiple of 4
    s.fill(4, '>')  # Pad at start instead
    s.fill(4, '1<5') # Pad at end with 1s to at least 5*4 bits. 

Original issue reported on code.google.com by dr.scott...@gmail.com on 24 Aug 2010 at 9:09

GoogleCodeExporter commented 9 years ago
Issue 112 has been merged into this issue.

Original comment by dr.scott...@gmail.com on 21 Jun 2011 at 8:59