Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

Python - having problem with bitstring cut method

Status
Not open for further replies.

ads-ee

Super Moderator
Staff member
Advanced Member level 7
Joined
Sep 10, 2013
Messages
7,944
Helped
1,823
Reputation
3,656
Reaction score
1,808
Trophy points
1,393
Location
USA
Activity points
60,209
I'm trying to use the cut method from bitstring and have been running into a discrepancy with the behavior called out on the example given under cut shows the following:

Code:
>>> s = BitString('0x1234')>>> for nibble in s.cut(4):
...     s.prepend(nibble)
>>> print(s)
0x43211234

Now on my Win7 64-bit system I have both the 2.7.8 and 3.4.1 win32 versions from python.org installed. The problem is both of them produce the following output instead.

0x11111234

Now in some respects it makes more sense, since s is being updated with the prepend method, but according to the example given, it seems that the generator s.cut(4) should be using a local copy of s in the for loop, while it iterates over the 4 nibbles. Instead it appears that the s bit array is being operated on directly, thereby adding a 1 nibble each time (which results in the next for loop iteration cutting the same 1 from s each time).

I've tried searching for more information on the bitstring module, but everything references back to the same pythonhosted.org site. I get the impression that this is a documentation problem, but want to make sure it's not something else like making s global or something (not sure python has globals, I've only just started learning it).

Thanks in advance for any insights into what is going on.

Regards
 

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top