This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Why this shift doesn't run?

Hi,

I've the following question about this code fragment:

...
char  BuffRX
xdata UCHAR BuffRX[10];
idata unsigned short ValCRCcomp;
idata unsigned short ValCRCappo;
idata unsigned short ValCRCappo2;

BuffRX[1] = 0x11;
BufRX[2] = 0x2A;
...
ValCRCappo = (unsigned short) (BuffRX[1] << 8);
ValCRCappo2 = (unsigned short) (BuffRX[2] | 0x0000);
ValCRCcomp = (unsigned short)  (ValCRCappo | ValCRCappo2);
...


Even the values in BuffRX[1] and BuffRX[2] are differents from zero, ValCRCcomp is always zero!

Any hints?

Thanks

Parents
  • char  BuffRX
    xdata UCHAR BuffRX[10];
    I'm surprised you don't get a duplicate symbols error (or something to that effect).
    ValCRCappo = (unsigned short) (BuffRX[1] << 8);
    The result is undefined if the shift count is greater than or equal to the width (in bits) of the value shifted, so that should be:
    ValCRCappo = (unsigned short)BuffRX[1] << 8;
    ValCRCappo2 = (unsigned short) (BuffRX[2] | 0x0000);
    BuffRX[2] is never assigned to, so is probably zero.

    "ValCRCcomp is always zero!"

    Given what we've seen above, I can believe it.

Reply
  • char  BuffRX
    xdata UCHAR BuffRX[10];
    I'm surprised you don't get a duplicate symbols error (or something to that effect).
    ValCRCappo = (unsigned short) (BuffRX[1] << 8);
    The result is undefined if the shift count is greater than or equal to the width (in bits) of the value shifted, so that should be:
    ValCRCappo = (unsigned short)BuffRX[1] << 8;
    ValCRCappo2 = (unsigned short) (BuffRX[2] | 0x0000);
    BuffRX[2] is never assigned to, so is probably zero.

    "ValCRCcomp is always zero!"

    Given what we've seen above, I can believe it.

Children
No data