Is there a tutorial on integer math, when to, when not to cast?
I'm using the Tiny44 with AVR Studio 4.16, and the latest Win-AVR.
I want to square a 16-bit variable. It's my 10-bit ADC value and place the result into a 32-bit variable. Thus having a maximum of 20 significant bits in a 32-bit variable.
uint16_t adcvalue uint32_t adcsquared adcvalue = ADCW; adcsquared = adcvalue * adcvalue;
do I need to force 32-bit math?
uint16_t adcvalue uint32_t adcsquared adcvalue = ADCW; adcsquared = (uint32_t)adcvalue * adcvalue;
When do I need to cast a lower bit variable to a higher bit variable during math operations.
A tutorial somewhere would be great. I searched the turorials section, but came up empty.
Thanks.