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
  • (test 16 ist declared as an unsigned int, the byte_high and byte_low
    as char)


    Shouldn't the chars also be unsigned?
    Otherwise, you're likely to run into sign-extension problems.

    also works fine (on the PC)! But the code doesn't work on the C167!

    Welcome to the world of platform-dependence!

    What size is an unsigned int on your PC?

    What exactly happens on your target? Have you tried stepping it in the simulator?

Reply
  • (test 16 ist declared as an unsigned int, the byte_high and byte_low
    as char)


    Shouldn't the chars also be unsigned?
    Otherwise, you're likely to run into sign-extension problems.

    also works fine (on the PC)! But the code doesn't work on the C167!

    Welcome to the world of platform-dependence!

    What size is an unsigned int on your PC?

    What exactly happens on your target? Have you tried stepping it in the simulator?

Children