0

is there a correct way to increment a uint8 string in big endian format? For example i have:

uint8 test[] = {0,0,0,1};

test[3]++; //works

but is also somehow an increment with an typecast in this way possible?

 *test = (uint32) *test+1; //doesnt work... Only the first test[0] will be incremented... 

Thank you.

Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328
Hub
  • 1

1 Answers1

0

How about this:

((uint32_t*)test)++;

But this still operates in native byte order.

If you have a buffer in network order, you should do this:

uint32_t *p = (uint32_t*)test;
uint32_t temp = ntohl(*p);
temp++;
*p = htonl(temp);
Jonathon Reinhart
  • 132,704
  • 33
  • 254
  • 328