Link to home
Start Free TrialLog in
Avatar of Mike Jacobs
Mike JacobsFlag for United Kingdom of Great Britain and Northern Ireland

asked on

BITCOUNT ALGORITHM? (to count the ones and zeroes in arbitrary stings)

Anyone know of a relatively straightforward algorithm for computing the numbers of ones and zeroes in an arbitrary string such that, we could address the function thus

Number_of_Ones=bitcount(arbitrary_string,1)
Number_of_Zeroes=bitcount(arbitrary_string,0)
Avatar of phoffric
phoffric

You want the code to be in R? You also have included the programming zone, which encompasses a lot of languages.

Number_of_Ones=bitcount("ABC",1)
Are you interested in analyzing the binary representation of these 3 chars, and then counting the number of bits that are 1.
ASKER CERTIFIED SOLUTION
Avatar of Dr. Klahn
Dr. Klahn

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Mike Jacobs

ASKER

@phophric

nope. Don't care about the individual characters. Just need to know the number of 1s and 0s

@ Dr Klahn
that looks like it will do the trick.  Thanks.
my main programming language is VFP but this query is not language specific. I may want to invoke it in Javascript, php, python or whatever. It's actually related to a test for whether or not a given bitstream has been transmitted using the "Chaffing and Winnowing" protocol described Ron Rivest, with a view to potential improvements to that protocol.
haven't yet implemented it but this is clearly a solution to the problem.