Skip to content

Instantly share code, notes, and snippets.

View dcvz's full-sized avatar

David Chavez dcvz

View GitHub Profile
@dcvz
dcvz / ones
Last active December 21, 2015 23:39
Return number of 1's in the binary representation of N
int ones(int n)
{
// base case
if (n < 2)
return n;
// recursive case
return n % 2 + ones(n/2);
}