I need to write a function:
f( b As Byte ) As Boolean
The function must return True if the value of b has 3 or less bits set. Otherwise, f returns False.
I can achieve this by converting b to a string using binary format then counting the number of '1's in the string, but I'd like to know if there's a more elegant way to do it.
Anyone care to have a go?




Reply With Quote