| Home | Trees | Indices | Help |
|---|
|
|
A sequence of bits, of arbitrary length. Has similar semantics to strings, in that a single index is itself a BitString (of unit length).
This is intended as a standard fmt for arbitrary binary data, to help with conversion between other types. In other words, convert to and from this, and then chain conversions.
BitStr are stored as a contiguous sequence in an array of bytes. Both bits and bytes are "little endian" - this allows arbitrary lengths of bits, at arbitrary offsets, to be given values without worrying about alignment.
The bit sequence starts at bit 'offset' in the first byte and there are a total of 'length' bits. The number of bytes stored is the minimum implied by those two values, with zero padding.
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
Inherited from |
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
|
|||
__swap = swap_table()
|
|||
|
|||
|
Inherited from |
|||
|
|||
value is a bytes() instance that contains the data. length is the number of valid bits. If given as a float it is the number of bytes (bits = int(float) * 8 + decimal(float) * 10) offset is the index of the first valid bit in the value.
|
Return a series of bytes values, which encode the data for len(self) bits when offset=0 (with final padding in the last byte if necessary). It is the caller's responsibility to discard any trailing bits. When 0 < offset < 8 then the data are zero-padded by offset bits first. |
For 64 bits or less, show bits grouped by byte (octet), with bytes and bits running from left to right. This is a "picture" of the bits. For more than 64 bits, give a hex encoding of bytes (right padded with zeros), shown in big-endian fmt. In both cases, the length in bits is given after a trailing slash. Whatever the internal offset, values are displayed with no initial padding.
|
|
|
Convert the entire bit sequence (of any size) to an integer. Big endian conversion is only possible if the bits form a whole number of bytes. |
|
Value can be an int, or a string with a leading or trailing tag. A plain int, or no tag, or leading tag, is byte little-endian by default. Length and big-endianness are inferred from the fmt for values given as strings, but explicit parameters override these. If no length is given, and none can be inferred, 32 bits is assumed (bit length cannot be inferred for decimal values, even as strings). The interpretation of big-endian values depends on the base and is either very intuitive and useful, or completely stupid. Use at your own risk. Big-endian hex values must specify an exact number of bytes (even number of hex digits). Each separate byte is assigned a value according to big-endian semantics, but with a byte small-endian order is used. This is consistent with the standard conventions for network data. So, for example, 1234x0 gives two bytes. The first contains the value 0x12, the second the value 0x34. Big-endian binary values are taken to be a "picture" of the bits, with the array reading from left to right. So 0011b0 specifies four bits, starting with two zeroes. Big-endian decimal and octal values are treated as hex values. |
| Home | Trees | Indices | Help |
|---|
| Generated by Epydoc 3.0.1 on Sat Jun 9 21:50:51 2012 | http://epydoc.sourceforge.net |