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 support@ccsinfo.com

words by words shifting after certain delay...

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



Joined: 20 Dec 2005
Posts: 112

View user's profile Send private message

words by words shifting after certain delay...
PostPosted: Mon Jan 09, 2006 8:53 pm     Reply with quote

Guys....

How can I do words by words shifting(like bits shifting)...
Ttelmah
Guest







PostPosted: Tue Jan 10, 2006 6:12 am     Reply with quote

There is no built in function, so you have to do this yourself. There are a number of approaches, depending on what you actually want to do. Remember that C itself contains shift operations for the data types, so for (say), an int32 variable:

val=val<<8;

Will move the bytes left by 8 bits (giving an effective *256). The compiler is also smart enough to replace this with byte moves, rather than 8 bit shifts. If though you want to work with (say), an array of bytes, then you should consider using a pointer, and updating this, rather than moving the data itself. I you look at the ex_sisr code (which shows a buffer used to handle serial data), here the pointer only is moved, rather than relocating the whole block of data. This is obviously more efficient, than moving large amounts of data around. Remember also, that a 'union', would allow you to declare a variable containing some data form, and in the same space, a byte array. Moving the data, then becomes a simple matter of manipulating this array. So:
(for a rotation, rather than a shift)
Code:


union rblock {
   int8 b[4];
   int32 val;
} value;

void rotate8(union rblock * v) {
   int8 temp;
   temp=v->b[3];
   v->b[3]=v->b[2];
   v->b[2]=v->b[1];
   v->b[1]=v->b[0];
   v->b[0]=temp;
}

//Called as

rotate8(&value);


Would perform a bytewise rotation on the int32 value 'value.val'.
So there are a lot of different approaches, depending on what you actually need to do. In general, if the amount of data involved is large, I'd definately consider moving a pointer, rather than the data itelf.

Best Wishes
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