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

onversion 8/16 bit types problem

Hi!

I've the following problem!
I receive via CAN a 16-Bit value, I'll use for some calculations on a
Siemens C167CR, und transmit the result again back via CAN!

The following code works fine on a PC:
(test 16 ist declared as an unsigned int, the byte_high and byte_low
as char)

test16 = byte_high;
test16 = test16 << 8;
test16 = test16 | byte_low;

The way back:

byte_low = test16;
byte_high = (test16 >> 8);

also works fine (on the PC)!

But the code doesn't work on the C167!
It seem's, that the C167 doesn't make the conversion back not correct.


Thanks for your tips!
SVEN

Parents
  • Remember, unsigned int on 32-bit OS's like Windows are 32-bits. For your 167, probably only 16. Be sure to always use unsigned vars. when bit shifting, including your chars. Try unsigned short on the PC to match the size of the 167's unsigned int.

    Like Andrew Neil (thanks Andrew) said, see my web page's Coding Conventions document for known size typedefs.

    - Mark

Reply
  • Remember, unsigned int on 32-bit OS's like Windows are 32-bits. For your 167, probably only 16. Be sure to always use unsigned vars. when bit shifting, including your chars. Try unsigned short on the PC to match the size of the 167's unsigned int.

    Like Andrew Neil (thanks Andrew) said, see my web page's Coding Conventions document for known size typedefs.

    - Mark

Children
No data