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 the Bits.

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



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

Shifting the Bits.
PostPosted: Sat Jan 26, 2008 12:40 am     Reply with quote

Hi,
i am using ccs compiler (version 4.020) and pic16f877a/pic16f870.
i have some data in a variable called (int16 x) and suppose x=1100100100110001
now what i want is that shift 1st 8bit to right so that the value in x read like that
x=0011000111001001.
i want to know that how this shifting can be done.can anyone give any example.
Humberto



Joined: 08 Sep 2003
Posts: 1215
Location: Buenos Aires, La Reina del Plata

View user's profile Send private message

PostPosted: Sat Jan 26, 2008 5:23 am     Reply with quote

Starting with the following 16 bit value:
x=1100100100110001
and shifting right >> 2 will become in:
x=0011001001001100
NOT in:
x=0011000111001001.

Quote:

now what i want is that shift 1st 8bit to right so that

1st 8 bit doesn't have any meaning and is ambiguous. It is better to refer as
Most Significant Byte (MSB) or Last Significant Byte (LSB)

Pls tell us exactly what do you need and we will help you.


Humberto
hayee



Joined: 05 Sep 2007
Posts: 252

View user's profile Send private message

PostPosted: Sat Jan 26, 2008 7:38 am     Reply with quote

hi,
thanks Humberto.
i have solved the problem by using rotate_left command.actually i want to shift the 8 msb bits at the lsb side and for this purpose i used rotate_left command 8 times.
Guest








PostPosted: Sat Jan 26, 2008 7:50 am     Reply with quote

As a comment though, if you want to effectively swap the bytes, you can do this very easily, by just using an 8bit 'temporary' variable, and 'make8' to take the LSB into this, and then make16 to put it together again. So:
Code:

int16 val=0b1100100100110001;
int8 temp;
temp=make8(val,0); //get the LSB
val=make16(temp,make8(val,1)); //move the MSB to LSB

This swaps the bytes in just three instructions, versus probably 16 or more usng the rotation.

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