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

int16 variable rotat_left()

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



Joined: 08 Aug 2005
Posts: 2

View user's profile Send private message

int16 variable rotat_left()
PostPosted: Tue Aug 09, 2005 2:25 pm     Reply with quote

I have declared a int16 variable and tried to perform a rotate_left() with it. When I try to observe the changes to the int16 variable in "File Register" watch window. I only see the lower 8 bit shfting.
ie.
/*****************************************************/
int16 var1;
var1 = 0x0001;

// so now the var1 should look like 00000000 00000010

for(i=0; i<=8; i++)
rotate_left(&var1, 1);

// the for loop should rotate the 1 into the upper byte

/*****************************************************/

What should I do? Is it something intrinsic of the rotate_left() or the data type int16? Thank you. Appreciate all your help
Ttelmah
Guest







PostPosted: Tue Aug 09, 2005 2:40 pm     Reply with quote

An int16, is two bytes long. You are telling the command to rotate one byte. You need:

rotate_left(&var1, 2);

You can let the compiler work this out for you (safer if you change data sizes later), using the 'sizeof' command. So:

rotate_left(&var1, sizeof(var1));

ensures the command rotates the entire variable.

Best Wishes
peterpan



Joined: 08 Aug 2005
Posts: 2

View user's profile Send private message

PostPosted: Tue Aug 09, 2005 3:15 pm     Reply with quote

thank you Ttelmah, it's working Very Happy
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