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

shift_left/right use

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



Joined: 30 Nov 2007
Posts: 10

View user's profile Send private message

shift_left/right use
PostPosted: Mon Dec 17, 2007 3:22 am     Reply with quote

Hello All;

If I want to shift 32-bits integer left or right by one bit what to put as byte count ?

Code:
bit_out = shift_left(number32, ??, bit_in);



Thanks
meereck



Joined: 09 Nov 2006
Posts: 173

View user's profile Send private message

PostPosted: Mon Dec 17, 2007 4:07 am     Reply with quote

see the compiler reference manual : http://ccsinfo.com/downloads/CReferenceManual.pdf
Quote:
shift_left (address, bytes, value)
address is a pointer to memory, bytes is a count of the number of bytes to work with, value is a 0 to 1 to be shifted in.
red_one



Joined: 30 Nov 2007
Posts: 10

View user's profile Send private message

PostPosted: Mon Dec 17, 2007 4:18 am     Reply with quote

meereck wrote:
see the compiler reference manual : http://ccsinfo.com/downloads/CReferenceManual.pdf
Quote:
shift_left (address, bytes, value)
address is a pointer to memory, bytes is a count of the number of bytes to work with, value is a 0 to 1 to be shifted in.


so what "count of the number of bytes to work with" does mean ?

32-bits = 4 bytes, should I take 4 as a count ?
Ken Johnson



Joined: 23 Mar 2006
Posts: 197
Location: Lewisburg, WV

View user's profile Send private message

PostPosted: Mon Dec 17, 2007 7:57 am     Reply with quote

Quote:

If I want to shift 32-bits integer left or right by one bit what to put as byte count ?


Sounds like you want this:

Code:

  int32  x;
 
  x <<= 1;  //  Shifts left 1 bit
  x >>= 1;  //  Shifts right 1 bit



Ken
treitmey



Joined: 23 Jan 2004
Posts: 1094
Location: Appleton,WI USA

View user's profile Send private message Visit poster's website

PostPosted: Mon Dec 17, 2007 9:30 am     Reply with quote

Yes!
4 is the count
int32,... 32bits... 8bits/byte ..... 32bits/8=4
aopg64



Joined: 17 Oct 2005
Posts: 28
Location: Hampshire, UK

View user's profile Send private message

Another shift_left/shift_right problem
PostPosted: Wed May 28, 2008 4:50 am     Reply with quote

Hi folks,

I'm trying to use common code to do reads and writes to a Microchip 25AA256 EEPROM from an 18F4620 using CCS V3.249.

I use a common command buffer (cmd[4]) and pass in a variable number (1 to 4) for the number of bytes in the command.

Unfortunately the shift functions only seem to allow a fixed number-of-bytes value.

I've tried size_t casting and so on.

Here's the code fragment:

Code:
void ExtEEPROM_SendCmd(uint8 NumBytes)
{
   uint8 i;

   ExtEEPROM_Select();

   for(i=0; i< (NumBytes*8) ; i++)
   {
      BB_ExternalEEPROM_PIC_SDO = shift_left(cmd,NumBytes,0);
      ExtEEPROM_LatchBit();
   }
}


It's the variable 'NumBytes' in the shift_left that the compiler objects to.

The CCS help file doesn't specify what data type this value should be. I've tried 16-bit casts too.Maybe it should be const'ed?

Anybody got any ideas? Or will I just have to code each command sequence individually?

TIA,

Nige
_________________
No comment! (Can't think of anything interesting to say!)
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