Re: algorithm to identify number from 0-16384 having at most 4 1s in its binary number
- From: "Ujjaval" <ujjaval@xxxxxxxxx>
- Date: 23 Jan 2006 19:22:33 -0800
Yes I need the numbers with at the most 4 1s or less than that. so i
also need numbers with 3 1s, 2 1s and 1 1s.
i didn't really get what Erik Naggum suggested. But I worked out the
following way:
n = 2^14
count = 0
for ( i=0;i< n;i++)
{
for (j=0;j<n;j=j*2)
{
if (i AND j) = j
count = count + 1
}
if (count <=4)
print i
}
This will print all the numbers having at most 4 1s in its equivalent
binary number.
What do you think of this??
.
- Follow-Ups:
- Re: algorithm to identify number from 0-16384 having at most 4 1s in its binary number
- From: James Waldby
- Re: algorithm to identify number from 0-16384 having at most 4 1s in its binary number
- From: Keith A. Lewis
- Re: algorithm to identify number from 0-16384 having at most 4 1s in its binary number
- From: Ed Hook
- Re: algorithm to identify number from 0-16384 having at most 4 1s in its binary number
- References:
- Prev by Date: Question about partial order
- Next by Date: Re: Cantorian pseudomathematics
- Previous by thread: Re: algorithm to identify number from 0-16384 having at most 4 1s in its binary number
- Next by thread: Re: algorithm to identify number from 0-16384 having at most 4 1s in its binary number
- Index(es):