Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Bitcount
Message
From
04/12/2014 08:24:53
Hilmar Zonneveld
Independent Consultant
Cochabamba, Bolivia
 
 
To
04/12/2014 07:23:05
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows 8.1
Network:
SAMBA Server
Database:
Visual FoxPro
Application:
Desktop
Miscellaneous
Thread ID:
01611745
Message ID:
01611797
Views:
38
>>>Hi all,
>>>
>>>Problem is I need to do do something as a multipple of the bits set on an integer, the integer is a bit array to store statii.
>>>
>>>I need to figure out how many bits are set on an integer.
>>>
>>>I know I can loop / iterate through the number and bittest / divide by 2 etc.
>>>
>>>for now there are not to much so I can do with an ICASE, but I like it generic :)
>>>
>>>Any ideas for a fast solution? Something mathematical?
>>>
>>>Lutz
>>
>>If it is a positive integer, the number of bits is related to the base-2 logarithm. You may need to experiment a bit; but I think the number of binary digits is something like: ceiling(log2(number)). Of course, Visual FoxPro doesn't have a log2() function, but that can be solved easily as ceiling(log(number) / log(2))
>
>0xC0 and 0x03 have the same number of bits set. Where does log2 come in ?

Sorry, I misunderstood the question.
Difference in opinions hath cost many millions of lives: for instance, whether flesh be bread, or bread be flesh; whether whistling be a vice or a virtue; whether it be better to kiss a post, or throw it into the fire... (from Gulliver's Travels)
Previous
Reply
Map
View

Click here to load this message in the networking platform