<Code>
int bitSeqTotal(int bitSeq)
{
int counter;
int total = 0;
for(counter = 0;counter < 8;counter++)
{
total += ((1 << counter) & bitSeq) ? counter : 0;
}
return total;
}
void fillBitSeqString(char *buf,int num)
{
for(int counter = 7;counter >= 0;counter--)
*(buf++) = ((1 << counter) & num) ? ''1'':''0'';
}
int _tmain()
{
int check = 0;
int num = 6;
char buf[20];
for(check = 0;check < 256;check++)
{
if(bitSeqTotal(check) == num)
{
fillBitSeqString(buf,check);
printf("%s\n",buf);
}
}
return 0;
}
</Code>
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement