M
Martin Wells
I have an array as follows:
char unsigned data[N];
I want to set every single bit in the array to 1. My initial thoughts
were:
memset(data, UCHAR_MAX, sizeof data);
but then when I looked at the declaration for memset, I saw that the
middle parameter was an int rather than an unsigned char. The problem
here is that UCHAR_MAX isn't guaranteed to "fit" in an int.
Can anyone think of a way to set all the bits to 1 (other than looping
through the elements and assigning UCHAR_MAX to them)?
Possibly, what I need is an int value that will convert to UCHAR_MAX
on every implementation... hmm...
Martin
char unsigned data[N];
I want to set every single bit in the array to 1. My initial thoughts
were:
memset(data, UCHAR_MAX, sizeof data);
but then when I looked at the declaration for memset, I saw that the
middle parameter was an int rather than an unsigned char. The problem
here is that UCHAR_MAX isn't guaranteed to "fit" in an int.
Can anyone think of a way to set all the bits to 1 (other than looping
through the elements and assigning UCHAR_MAX to them)?
Possibly, what I need is an int value that will convert to UCHAR_MAX
on every implementation... hmm...
Martin