Theremingenieur
Senior Member+
I wanted to create a function which multiplies a uint32_t with a uint16_t and with another uint16_t which would give a uint64_t result. That did not work on my Teensy 3.1.
Printing a uint64_t with Serial.print() gives a compiler error, obviously there is a prototype missing :
does not compile, it says "error: call of overloaded 'print(uint64_t&)' is ambiguous".
So, I tried to divide my resulting uint64_t up into two uint32_t (upper and lower):
The result is : "0 + 8BFF5FE". That means that the upper half of the uint64_t is either not calculated or it is truncated.
What am I doing wrong???
Thank you in advance for your help!
Printing a uint64_t with Serial.print() gives a compiler error, obviously there is a prototype missing :
Code:
Serial.begin(57600);
delay(1000);
uint64_t result = (uint32_t)0x6459D01A * (uint16_t)0x803B;
Serial.print(result);
So, I tried to divide my resulting uint64_t up into two uint32_t (upper and lower):
Code:
Serial.begin(57600);
delay(1000);
uint64_t result = (uint32_t)0x6459D01A * (uint16_t)0x803B;
uint32_t lower = result & 0xFFFFFFFF;
uint32_t higher = (uint64_t)result >> 32;
Serial.print(higher, HEX);
Serial.print(" + ");
Serial.print(lower, HEX);
The result is : "0 + 8BFF5FE". That means that the upper half of the uint64_t is either not calculated or it is truncated.
What am I doing wrong???
Thank you in advance for your help!
Last edited: