In a Rx3i what would be the most efficient way to count the number of bits set in a word variable?
The naive approach is to simply shift the bits out of the word and count the ones that are set. But is this the smartest way of doing it?
One smarter example is Brian Kernighan’s Algorithm which has the advantage that it only loops for the number of bits that are set in the number. And while I have no problem implementing it in ladder code I have no idea if this is the best way in an Rx3i.
So am I missing any tricks?
The naive approach is to simply shift the bits out of the word and count the ones that are set. But is this the smartest way of doing it?
One smarter example is Brian Kernighan’s Algorithm which has the advantage that it only loops for the number of bits that are set in the number. And while I have no problem implementing it in ladder code I have no idea if this is the best way in an Rx3i.
So am I missing any tricks?
Last edited: