This thread has been locked.

If you have a related question, please click the "Ask a related question" button in the top right corner. The newly created question will be automatically linked to this question.

MSP430F5659: bitwise shifting left over 15 results in 0

Part Number: MSP430F5659

Hi,

I am trying to use uint32_t variables as error flags.

bit shifting over 2 bytes results in a value of 0x0000 however, even when stored in a uint32_t

How can I set bits in the 3rd and 4th bytes of a uint32_t?? Thanks!

#include "stdint.h"

void main() {

uint32_t test = 0;

test |= (1<< 16);

if(test) {

return 0;

}

else {

return -1

}

}

  • Try:  test |= (uint32_t)1 << 16;

    Else, I believe the compiler will assign 1 as an "int", which is only 16-bits in this architecture and will overflow.

    Take a look at the compiler generated output.  There should have been a warning about this.

**Attention** This is a public forum