# Thread: a large hex counter

1. ## a large hex counter

I need to make a counter using hex
I want an array of length 10 to be updated each cycle with the next hex number.
0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 1
...
0 0 0 0 0 0 0 0 0 15
0 0 0 0 0 0 0 0 1 0
...
15 15 15 15 15 15 15 15 15 15

I previously handled any counter in a different base by having a huge decimal counter then converting it to the appropriate base.
Unfortunately a long is only 4 bytes and can't handle 16^10
I can't use doubles with my previous method either because the mod (%) operator doesn't work with them.

Not sure if I explained the problem well enough (tell me so with a reply)
Any ideas?

2. ## Wait a moment...

After much thought I've decided its just easier to splt the array into 2 hence halving the max decimal number
No redesigning for me =)

3. You could always go with brute force.
Code:
```#include <stdio.h>

#define SIZE 10

static void clear(unsigned *counter, int from)
{
int i;

for (i = from; i < SIZE; i++)
counter[i] = 0x0;
}

static void print(unsigned *counter)
{
int i;

for (i = 0; i < SIZE; i++)
printf("%x|", counter[i]);

fflush(stdout);
printf("\r");
}

int main(void)
{
unsigned counter[SIZE] = {0};
int i;

while (1)
{
counter[SIZE - 1]++;

for (i = SIZE - 1; i > 0; i--)
{
if (counter[i] == 0x10)
{
counter[i - 1]++;
clear(counter, i);
}
}

if (counter[0] == 0x10)
break;

print(counter);
}

printf("\n");

return 0;
}```