Skip to content

Commit 22a8726

Browse files
karldingfelixdivo
authored andcommitted
Clean up bits generator TODO in PCAN interface
Remove the TODO to document how the bits generator works in the PCAN interface by adding documentation and renaming the variables to make things more clear.
1 parent baf212d commit 22a8726

File tree

1 file changed

+10
-4
lines changed

1 file changed

+10
-4
lines changed

can/interfaces/pcan/pcan.py

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -216,11 +216,17 @@ def _get_formatted_error(self, error):
216216
"""
217217

218218
def bits(n):
219-
"""TODO: document"""
219+
"""
220+
Iterate over all the set bits in `n`, returning the masked bits at
221+
the set indices
222+
"""
220223
while n:
221-
b = n & (~n+1)
222-
yield b
223-
n ^= b
224+
# Create a mask to mask the lowest set bit in n
225+
mask = (~n + 1)
226+
masked_value = n & mask
227+
yield masked_value
228+
# Toggle the lowest set bit
229+
n ^= masked_value
224230

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

0 commit comments

Comments
 (0)