View previous topic :: View next topic |
Author |
Message |
red_one
Joined: 30 Nov 2007 Posts: 10
|
shift_left/right use |
Posted: Mon Dec 17, 2007 3:22 am |
|
|
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
|
|
Posted: Mon Dec 17, 2007 4:07 am |
|
|
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
|
|
Posted: Mon Dec 17, 2007 4:18 am |
|
|
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
|
|
Posted: Mon Dec 17, 2007 7:57 am |
|
|
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
|
|
Posted: Mon Dec 17, 2007 9:30 am |
|
|
Yes!
4 is the count
int32,... 32bits... 8bits/byte ..... 32bits/8=4 |
|
|
aopg64
Joined: 17 Oct 2005 Posts: 28 Location: Hampshire, UK
|
Another shift_left/shift_right problem |
Posted: Wed May 28, 2008 4:50 am |
|
|
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!) |
|
|
|