|
-
July 22nd, 2010, 04:25 AM
#14
Re: All combinations of 0's and 1's in 128 bit character array?
 Originally Posted by Lucky75
Mhm, that would work fine if I was just printing, but I need to actually store it in a 16 byte character array and pass it to another function.
And calling next_permutation on the character array directly would just swap the different combinations of bytes instead of the individual bits, wouldn't it??
The vector already holds an internal 16-byte elements array.
If you do
Code:
unsigned char * p = (unsigned char *)&v[0];
some_otherfunction_expecting_a_16bytes_array(p);
where v is one of the permutations you got the pointer p would point to a 16-elements array.
If you want to copy the array to fixed-sized char array, you would/could do
Code:
unsigned char arr[16] = { '\0' };
unsigned char * p = (unsigned char *)&v[0];
memcpy(arr, p, min(sizeof(arr), v.size() * sizeof(v[0])));
The min is only to make sure that the vector really has 16 elements of type char, same as the arr.
Regards, Alex
Last edited by itsmeandnobodyelse; July 22nd, 2010 at 04:27 AM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|