??? 12/06/06 12:57 Modified: 12/06/06 13:03 Read: times |
#129068 - That makes _a lot_ more sense. Responding to: ???'s previous message |
yes sir my problem is something like that i have (buff[96]) array of 96 bytes, and in that locations i have stored some hex locations for my particular requirement and after that i want to shift the array element by one location and in the last location i have to insert another hex location from another array .. and it will continue till my all hex locations are inserted from another array locations ..
That sheds quite a bit of light on what the actual question is. As some other posters have mentioned already, you might want to familiarize yourself with the concept of circular buffers. They are used quite often and being familiar with how they work and how to implement them is ... very useful, to say the least. Shifting 96 bytes around everytime you add a new element to your array is very slow and cumbersome, especially on a '51. There are other architectures that have instruction set support for this type of operation (various kinds of DSPs), or hardware support (DMA controllers), but even then you will need a very good reason to do this instead of using a circular buffer. How do circular buffers work ? Instead of moving the data in the buffer, you move the index at which your data begins. This is done by using a pointer or a variable with the index. So instead of adding an element by doing unsigned char array[ARRAY_SIZE]; ... for(i = ARRAY_SIZE - 1; i > 0; i--) array[i] = array[i - 1]; array[0] = some_new_data; is is inserted by unsigned char array[ARRAY_SIZE]; ... array[start_index] = some_new_data; start_index = start_index + 1; if(start_index >= ARRAY_SIZE) start_index = 0; Of course, you need to take care that your index wraps around correctly, or you'll end up writing data outside the array, which would be a pretty bad bug. The modulo operator '%' can be quite useful for implementing the wraparound. However, on a '51, it might be slower than using an if statement. |
Topic | Author | Date |
shifting array elements using bitwise opeartor inC | 01/01/70 00:00 | |
Why? | 01/01/70 00:00 | |
Elaborate please. | 01/01/70 00:00 | |
opeartor inC | 01/01/70 00:00 | |
Possibly not | 01/01/70 00:00 | |
Possibly not | 01/01/70 00:00 | |
No, it doesn't | 01/01/70 00:00 | |
*nitpick* | 01/01/70 00:00 | |
Ah yes | 01/01/70 00:00 | |
may be not! | 01/01/70 00:00 | |
We will never know ... | 01/01/70 00:00 | |
my actual problem | 01/01/70 00:00 | |
do not shift at all | 01/01/70 00:00 | |
Circular buffer | 01/01/70 00:00 | |
it's bytewise then, isn't it | 01/01/70 00:00 | |
That makes _a lot_ more sense. | 01/01/70 00:00 | |
just a small remark | 01/01/70 00:00 | |
My bad.![]() | 01/01/70 00:00 |