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.

[参考译文] LP-MSP430FR2476:UINT 左移乘法截断

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

https://e2e.ti.com/support/microcontrollers/msp-low-power-microcontrollers-group/msp430/f/msp-low-power-microcontroller-forum/1071072/lp-msp430fr2476-uint-left-shift-multiply-truncating

部件号:LP-MSP430FR2476

我正在尝试使用比例因子执行乘法。 我在 CCS 中看到的结果不正确。 这种类型的乘法是否可行?

UINT16_t 标量 FactorMult (uint16_t 数据){
UINT64_t cellVolt =0;
UINT16_t 通道电压;
UINT64_t xTwo12 = 0;
UINT64_t xTwo9 = 0;
UINT64_t xTwo7 = 0;
UINT64_t xTwo5 = 0;

xTwo12 |=数据<<12U;
xTwo9 |=数据<<9U;
xTwo7 |=数据<<7U;
xTwo5 |=数据<5U;
cellVolt |= xTwo12;
cellVolt |= xTwo9;
cellVolt |= xTwo7;
cellVolt |= xTwo5;

}

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

    您正在移动一个16位整数,结果将始终为16位。 如果您需要64位结果,则必须在转换16位整数之前将其强制转换为64位整数。 这就是 C 的一贯运作方式。 例如:

    xTwo12 |= (uint64_t)data << 12u;