# Convert Ccs Shift_right/shift_left To Boostc?

## Recommended Posts

Hello,

How do I convert ccs shift_right()/shift_left() functions to boostc?

(I have seen some example code in this forum to convert to c2c, but that code doesn't compile in boostc)

Regards,

Marcel

##### Share on other sites

C has two shift operator << and >>.

eg

x = y << 3; // y is left shifted 3 bits , the result is stored in x.

z = w >> t; // w is right shifted according to the contents of t, result stored in z

beware

wrong

y<<2;// y is shifted left two places but the result is not stored so y stays the same

correct

y = y << 2;

note that zeros are always shifted in, there is no arithmetic shift

You should consult a C manual for more detail

Hello,

How do I convert ccs shift_right()/shift_left() functions to boostc?

(I have seen some example code in this forum to convert to c2c, but that code doesn't compile in boostc)

Regards,

Marcel

##### Share on other sites

this seems to work :

from ccs:

shift_right(&data,1,input(X10_TO_PIC));

to boostc :

data >>= 1;

if ((portb & X10_TO_PIC)==0)

data &= 0x7F;

else

data |= 0x80;

Edited by mhwlng
##### Share on other sites
this seems to work :

from ccs:

shift_right(&data,1,input(X10_TO_PIC));

to boostc :

data >>= 1;

if ((portb & X10_TO_PIC)==0)

data &= 0x7F;

else

data |= 0x80;

Neater still:

```#define X10_TO_PIC portb.0
...
...
data >>= 1;
data.7 = X10_TO_PIC;```

Regards

Dave

##### Share on other sites

Hi Dave,

so how do I use a bit field, if the variable is a pointer :

```void x10_read_bits(char n,char *data1,char *data2)
{
...
*data1 >>= 1;
(*data1).7 = portb.0;  <-- doesn't work
...```

Thanks,

Marcel

## Join the conversation

You are posting as a guest. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.