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.
I am trying to implement a multiplication with a scale factor. I am not seeing correct results in CCS. Is this type of multiplication possible to do?
uint16_t scaleFactorMult(uint16_t data){
uint64_t cellVolt = 0;
uint16_t channelVolt;
uint64_t xTwo12 = 0;
uint64_t xTwo9 = 0;
uint64_t xTwo7 = 0;
uint64_t xTwo5 = 0;
xTwo12 |= data << 12u;
xTwo9 |= data << 9u;
xTwo7 |= data << 7u;
xTwo5 |= data << 5u;
cellVolt |= xTwo12;
cellVolt |= xTwo9;
cellVolt |= xTwo7;
cellVolt |= xTwo5;
}
You are shifting a 16 bit integer and the result will always be 16 bits. If you what you want is a 64 bit result, you have to coerce the 16 bit integer into a 64 bit integer before shifting it. That is the way C has always worked. For example:
xTwo12 |= (uint64_t)data << 12u;
**Attention** This is a public forum