Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Clean up bits generator TODO in PCAN interface #588

Merged
merged 1 commit into from
May 16, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 10 additions & 4 deletions can/interfaces/pcan/pcan.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,17 @@ def _get_formatted_error(self, error):
"""

def bits(n):
"""TODO: document"""
"""
Iterate over all the set bits in `n`, returning the masked bits at
the set indices
"""
while n:
b = n & (~n+1)
yield b
n ^= b
# Create a mask to mask the lowest set bit in n
mask = (~n + 1)
masked_value = n & mask
yield masked_value
# Toggle the lowest set bit
n ^= masked_value

stsReturn = self.m_objPCANBasic.GetErrorText(error, 0)
if stsReturn[0] != PCAN_ERROR_OK:
Expand Down