I was wondering if anyone could find a better solution to this code i wrote.
The purpose of this function is to simply tell me how many bits are flagged in a long integer.
I figured there may be some sort of magical equation (which i am not currently seeing) that could possibly cut down most of the looping.
Thanks in advanced for any time you spend on this.
Code:Public Function FindLetterCount(ByVal pValue As Long) As Byte Dim MyCnt As Byte Dim i As Long For i = 30 To 0 Step -1 MyCnt = MyCnt + Abs(CBool(pValue And (2 ^ i))) Next i FindLetterCount = MyCnt End Function




Reply With Quote
