this code is working for a counter of 6 bit and i need a counter of 48 bit ... if u have time kindly try it..... i try alot but not succeed

#include<stdio.h>
#include<stdlib.h>
#include<float.h>
#include<math.h>
#include <time.h>
#include <cstdlib>
#include <iostream>
#include<stdint.h>
#include<conio.h>

int main()
{

 int a[64][6];
 int  i,j,k,d,c,n;
for(k=0;k<64;k++) //6 digit binary so 2^6 =64 is no: of combinations 
{
    for(j=0;j<6;j++)
    {
        a[k][j]=0;
    }
}
for(i=0;i<64;i++)
{
    n=i;
    for(j=5;j>=0;j--)
    {
        while(n!=0)
        {
            a[i][j]=n%2;
            j--;    
            n=n/2;      
        }
    }
}
for(k=0;k<64;k++)
{
    for(j=0;j<6;j++)
    {
        printf("%d",a[k][j]);
    }
    printf(" .................%d\n",k);
}
//printf("\n **** KHATAM SHo ****\n");
    getch();
    return 0;

}



help please

Dani AI

Generated

This thread already shows two useful directions: ’s array-based 6‑bit table (fine for 64 rows) and ’s idea to generate bitstrings rather than try to store everything. The crucial point missing is the scale: a 48‑bit counter is not just “a bit bigger” — it’s astronomically larger, and that affects any practical implementation.

2^48 = 281,474,976,710,656 combinations. If each combination is written as 48 ASCII characters plus a newline (49 bytes) the total output is 13,792,273,858,822,144 bytes (≈13.8 PB decimal, ≈12.25 PiB). Packing each value as 6 raw bytes (48 bits) reduces that to 1,688,849,860,263,936 bytes (≈1.689 PB, exactly 1.5 PiB), but it’s still huge. At a million combinations/second printing text, enumeration would take on the order of 9 years; at 1 billion/second it’s about 3.3 days. Console printing and per-line formatting are far slower than raw binary streaming, so don’t assume “it will finish soon.”

If the goal is to enumerate (not store) all 48‑bit patterns, treat each pattern as a 48‑bit integer and stream its bits on the fly. That avoids huge memory use and is simple and fast enough for practical rates (modulo the total time above). Example (C++):

#include <iostream>
#include <bitset>
#include <cstdint>

int main() {
    const std::uint64_t limit = static_cast<std::uint64_t>(1) << 48;
    for (std::uint64_t i = 0; i < limit; ++i)
        std::cout << std::bitset<48>(i) << '\n';
}

For disk storage use buffered binary output and pack 48 bits into 6 bytes to save ~8× space. If only a subset is needed, sample indices or generate specific indices on demand (bit shifts give the k‑th pattern directly). For low‑overhead iteration with minimal bit flips, consider Gray code. Above all, do not try to allocate a table with 2^48 rows in memory — streaming and index arithmetic are the only practical paths.

Recommended Answers

All 4 Replies

Such C++ includes in C code. The way you do it will become problematic when using 48 bits as the amount of possible permutations is huge. You don't have to store them though and just output them as they get calculated. Another thing that might become an issue is the use of counters (depending on how you do it). You could use an unsigned long long which is guaranteed to be 64 bits but it's a C99 standard feature. I'd go for re-writing the alghorithm though.

Depending on what your goal is exactly you could use a string. A quick attempt using a recursive method would result in something like this:

#include <stdio.h>

#define BIT_COUNT (6)

void print_bits(int bitcount, char* bitstring, int offset)
{
    if (bitcount == 0)
    {
        printf("%s\n", bitstring);
    }
    else
    {
        bitstring[offset] = '0';
        print_bits(bitcount - 1, bitstring, offset + 1);

        bitstring[offset] = '1';
        print_bits(bitcount - 1, bitstring, offset + 1);
    }
}

int main()
{
    char bits[BIT_COUNT + 1];
    bits[BIT_COUNT] = '\0';

    print_bits(BIT_COUNT, bits, 0);

    return 0;
}

, will your program exactly solve my problem ? ay i use it ?

It's more of a hint/possible solution towards what you need. As mentioned in the post it's something I quickly wrote down to show the idea of using a string you manipulate. It should work for an arbitrary bit count though, although I'm sure performance-wise it could be improved on.

You may use it, sure, but if you don't understand what's going on I don't see much of a point. I'll let you decide what you think is best for yourself.

-edit-

gonbe i tried to modify ur code for my problem but could't achieve, what i wanted

You should only have to change the define from 6 to 48. If that doesn't result in what you want I don't think I understand your problem correctly. If you set 48 it will take forever to finish, but that is to be expected with 2^48 strings that have to be calculated and printed. The logic of it should work. I'm not sure if I have time tomorrow to try to fix your existing code, it will probably be monday at the earliest if at any time. Try to figure out in the meanwhile what's going wrong and post your attempt(s). The bits increase, but that doesn't matter too much for the application's logic.

commented: gonbe i tried to modify ur code for my problem but could't achieve, what i wanted, so if you can possibly make any changes within my code to make it work for 48 bits then please resolve it, i wasted a whole lot of time on it, Help would be appreciated de +0

: thanks alot bro, lemme try it , if it worked i will let you know

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.