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:按位向左移动超过15会产生0

Guru**** 2513185 points


请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1007631/msp430f5659-bitwise-shifting-left-over-15-results-in-0

器件型号:MSP430F5659

您好!

我尝试使用 uint32_t 变量作为错误标志。

然而、即使存储在 uint32_t 中、超过2个字节的位移也会产生0x0000的值

如何设置 uint32_t 的第3个字节和第4个字节中的位? 谢谢!

#include "stdint.h"

void main(){

uint32_t test = 0;

测试 |=(1<<16);

if (test){

返回0;

否则{

返回-1

  • 请注意,本文内容源自机器翻译,可能存在语法或其它翻译错误,仅供参考。如需获取准确内容,请参阅链接中的英语原文或自行翻译。

    尝试: test |=(uint32_t) 1 << 16;

    否则、我相信编译器会将1指定为"int"、在该架构中该值仅为16位、并将溢出。

    请看一下编译器生成的输出。  应该对此发出警告。