View previous topic :: View next topic |
Author |
Message |
gautel
Joined: 04 Apr 2011 Posts: 3
|
help with writing "shift_right" in regular c langu |
Posted: Mon Apr 04, 2011 8:01 am |
|
|
Hello!
i have a problem with this function:
shift_right(RFbuffer+RFbuffer_index, 1, bitValue)
Can anyone please explain what it does? i understand that it should shift the bit's right, but not what happens when you write "RFbuffer+RFbuffer_index" as the variable.
I am currently working on a RFID reader using the CCS code for EM4095. And my problem is that i don't have very much experience using the CCS compiler, so i'm trying to write the code in knudsen C compiler.
I would be very grateful if someone could help me! _________________ student at Høyskolen i Gjøvik |
|
|
gautel
Joined: 04 Apr 2011 Posts: 3
|
|
Posted: Mon Apr 04, 2011 8:05 am |
|
|
i should add that "RFbuffer" is an array, and "RFbuffer_index" is an integer! _________________ student at Høyskolen i Gjøvik |
|
|
Ttelmah
Joined: 11 Mar 2010 Posts: 19553
|
|
Posted: Mon Apr 04, 2011 9:10 am |
|
|
It shifts right the single byte at character location 'RFbuffer_index', in the array 'Rbuffer', shifting _in_ the value 'bitValue' to the vacated space, and returns the bit shifted out the bottom.
Since RFBuffer is int8, it'd be roughly equated in ANSI C by:
Code: |
int8 shift_right(int8 *locn, int8 count, int8 val){
int8 rval=0
if (locn[count] & 1)
rval=1; //value to return
locn[count]/=2; //use division, since in C no guarantee that >>
//does not wrap.
if (val)
locn[count]|=128;
return rval;
}
|
Best Wishes |
|
|
gautel
Joined: 04 Apr 2011 Posts: 3
|
|
Posted: Mon Apr 04, 2011 9:29 am |
|
|
Thank you very much for the help! _________________ student at Høyskolen i Gjøvik |
|
|
|