i need fastest method to revers order of bytes in my char array.
for example i have:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19
unsignedchar buf[8];
// consider data stored in buf is 88 77 66 55 44 33 22 11
// how to reverse it to: 11 22 33 44 55 66 77 88
// currently i can do it by equal assignment , i make another buf like:
unsignedchar buf_ok[8];
buf_ok[0]=buf[7];
buf_ok[1]=buf[6];
buf_ok[2]=buf[5];
buf_ok[3]=buf[4];
buf_ok[4]=buf[3];
buf_ok[5]=buf[2];
buf_ok[6]=buf[1];
buf_ok[7]=buf[0];
// This does revers the bytes as i want but its very slow , i am looking for fast method ..
thanks i test and find execution time ... i am running a for loop that generate bytes , using this above assignment i am able to generate 30,000 8 bytes of keys / second i want to increase speed ...
I don't know how you are testing this but note that if the you don't use the result of the code you are testing the compiler might optimize away too much. For example, in the code you posted, if the buf_ok array is never used later in the code the compiler could simply ignore lines 7-16.
The results are by using buf_ok array and assignments as mentioned in 1st post.
i wanted alternate way to reverse the bytes order , in program i think i have big endian and littel endian formate problem with revers the input array i am researching on it , finding different ways to speed up my program ...
currently the program read my array all functions works correctly , it dont ignor any line ..