[Icc-avr] Calculations

Andy Syms asyms at technosoft.co.uk
Mon Jan 7 07:09:33 PST 2008


> temp2 = 0/(16L*baudrate)-1;    // Results into 65535

> I guess that the last calculation error is because of
> some rounding problem but obviously the correct answer is 0.

No.  0 - 1 is -1 which, if temp2 is an unsigned int would be represented as
0xffff, ie 65535.

Don't forget that division takes precedence over subtraction.

Andy

--
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
>>
>>  Andy Syms        Technosoft Systems Ltd
>>
>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>





More information about the Icc-avr mailing list