Assume that you have an array of uint8_t in C with the size of the array to be 10. I want to generate all possible binary combinations with these 80 bits, inside the array.
This could be implemented with 10 nested loops one for every element of the array. However, when you don't know the size then you cannot dynamically change the number of nested loops.
Is there any recursive method so that you can consider this 80 bit as a single number and count from 000000000..... up to 1111111111.... where the number of zeros and ones are equal to 80?
I considered the GNU gmp but the largest number is 1024 bits and you cannot access them as simple bits that represent actual numbers.
All I want to make is a big counter, that counts from 0 up to 2^80 but inside the array.
I want to give an example. Array of uint8_t with two bytes:
|00000000|00000000|
|00000000|00000001|
|00000000|00000010| . . .
|00000000|11111111|
|00000001|00000000|
|00000001|00000001|
|00000001|00000010|
. .
#include <gmp.h>
#include <stdio.h>
#include <assert.h>
int main()
{
mpz_t n;
int flag;
//Initialize the number.
mpz_init(n);
mpz_set_ui(n,0);
//Add one to the number */
mpz_add_ui(n,n,1); /* n = n + 1 */
}
How would you access the number n and copy the contents to your array?
memcpy(array, &n, 10) ?


