CCS C Software and Maintenance Offers
FAQFAQ   FAQForum Help   FAQOfficial CCS Support   SearchSearch  RegisterRegister 

ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

CCS does not monitor this forum on a regular basis.

Please do not post bug reports on this forum. Send them to CCS Technical Support

Shifting a byte in an Array

 
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion
View previous topic :: View next topic  
Author Message
David21
Guest







Shifting a byte in an Array
PostPosted: Wed Jun 07, 2006 2:25 pm     Reply with quote

I have an array, string[10] and string[10]=0xF.

Is there an operator that will shift the 0xF byte @ index 10 to index 9? I tried to shift_left and<< but they didn't work. Maybe i'm not using it right.

Thanks a bunch!
Ttelmah
Guest







PostPosted: Wed Jun 07, 2006 2:43 pm     Reply with quote

If you just want to move the contents of array[10] to array[9], then simply:
array[9]=array[10];

However assuming you want to move the whole array (the << operator, shifts the _bits_ inside a variable, not the variable itself):

memmove(&array[0],&array[1],10);

Shift_left, can do it, but is more inefficient (you would need to repeat it eight times, for the whole array...), a total of eighty moves...

As I have posted to another thread, it is also worth considering not actually moving the data, but just you access it. ex_sisr, does this for the array holding the incoming data, just moving an address through the array, and 'wrapping' it at the end, so the data itself does not have to move.

Best Wishes
david21
Guest







PostPosted: Wed Jun 07, 2006 2:48 pm     Reply with quote

what i'm trying to do is a FIFO type of buffer. I need every byte to shift down once. Thanks for the help!

Idea
Guest








PostPosted: Wed Jun 07, 2006 3:00 pm     Reply with quote

so
memmove(&array[0],&array[1],10);
would move every elements from 2 to 10 to index 1?
Ttelmah
Guest







PostPosted: Wed Jun 07, 2006 3:04 pm     Reply with quote

The memmove, will move element1, to element0, element2 to element1..... element10 to element9.
There are a total of eleven 'elements', but only 10 moves needed.
However for a FIFO buffer, look at the code in ex_sisr. Moving all the data, every time a byte is added/removed, is _very_ labour intensive. This is what circular buffers ar for (implemented in ex_sisr).

Best Wishes
GEUST
Guest







PostPosted: Wed Jun 07, 2006 3:06 pm     Reply with quote

THANKS. Cool
rberek



Joined: 10 Jan 2005
Posts: 207
Location: Ottawa, Canada

View user's profile Send private message

PostPosted: Wed Jun 07, 2006 3:22 pm     Reply with quote

I second Ttelmah's observation regarding using moveable pointers rather than moveable data.

When we design FIFOs in ASICs and FPGAs, the data never moves unless it is a trivially small FIFO that can be implemented in flipflops. Most FIFOs are implemented in memory structures, and there is no simple mechanism for shifting all the data, let alone in a small number of clock cycles, as is often required. Thus the simple solution of shifting read and write pointers, and having some logic to make sure they don't pass each other (i.e. an underflow), or that they don't get farther apart than the memory is deep (i.e. an overflow).

Just mentioning this as this is a good habit to get into should you need to write time-critical code.
Display posts from previous:   
Post new topic   Reply to topic    CCS Forum Index -> General CCS C Discussion All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group