Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Re: struct.pack and perl's 'B' code for bitstrings

Reply
Thread Tools

Re: struct.pack and perl's 'B' code for bitstrings

 
 
Oren Tirosh
Guest
Posts: n/a
 
      06-28-2003
On Fri, Jun 27, 2003 at 02:19:35PM -0600, Justin Johnson wrote:
> Is there anything equivalent to perl's pack code B, which allows you to
> specify bits to pack? For example, in perl, pack('B8', '00000010') will
> return 8 bits exactly as the bit string appears. I don't see any similar
> codes in struct.pack. In general struct.pack is not as robust as perl's
> pack function.


Are you using the word 'robust' to mean 'featureful'?

> Is there a better version of struct somewhere, or how are
> people overcoming some of these problems?


I've heard of some alternative version of struct. I've never checked if
they have bitstring options. When I need something like this I just use
the int or long constructor with radix 2:

>>> struct.pack('B', int('00000010', 2))

'\x02'

>>> struct.pack('>H', int('0001001000011000', 2))

'\x12\x18'

Oren

 
Reply With Quote
 
 
 
 
Troy Melhase
Guest
Posts: n/a
 
      06-28-2003
>> Is there a better version of struct somewhere, or how are
>> people overcoming some of these problems?

>
> I've heard of some alternative version of struct. I've never checked if
> they have bitstring options.


Justin, Oren:

You might be thinking of (or interested in) the SuperStruct module by Just
van Rossum:

http://starship.python.net/crew/just/code/sstruct.py

Or the unavailable-except-by-google-cache Python xstruct module:

http://216.239.57.100/search?q=cache...hl=en&ie=UTF-8

Good luck,
troy


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
what is the difference between code inside a <script> tag and code in the code-behind file? keithb ASP .Net 1 03-29-2006 01:00 AM
code behind AND page code a@b.com ASP .Net 2 01-09-2006 10:51 PM
Code reuse, code behind, and can't inherit since already inheritsPage Randall Parker ASP .Net 2 11-01-2005 06:59 PM
What's the difference/advantages between code behind and code inside? Alan Silver ASP .Net 37 02-10-2005 03:11 PM
Fire Code behind code AND Javascript code associated to a Button Click Event =?Utf-8?B?Q2FybG8gTWFyY2hlc29uaQ==?= ASP .Net 4 02-11-2004 07:31 AM



Advertisments