[Icc-avr] Calculations
Johan H. Bodin
jh.bodin at telia.com
Mon Jan 7 07:00:54 PST 2008
Bengt,
0 - 1 = -1 = 0xFFFF in 16-bit two-complements notation. 65535 if printed
as an unsigned int/short.
Bengt Ragnemalm skrev:
> Hi!
>
>
>
> I have spent some of my spare time during Christmas solving some strange
> problems I have had with a design. My problems was something completely
> different but I ended up with this:
>
>
>
> - I have found a calculation that may be a compiler error.
>
>
>
> This is my test code, baudrate is 38400:
>
>
>
> #define F_CPU 7372800
>
>
> temp2 = F_CPU/(16L*baudrate)-1; // Normal calculation, result OK
> 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.
>
>
>
> /Bengt
>
> ________________________________________________________________
>
> Bengt Ragnemalm Tel +46 13 22 24 97
>
> Research engineer FAX: +46 13 10 19 02
>
> Linköpings Universitet
> mailto:bengt.ragnemalm at imt.liu.se
>
> Inst. för Medicinsk Teknik Internet: http://www.imt.liu.se
> <http://www.imt.liu.se/>
>
> S-581 85 Linköping SWEDEN
>
>
>
>
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Icc-avr mailing list
> Icc-avr at imagecraft.com
> http://dragonsgate.net/mailman/listinfo/icc-avr
More information about the Icc-avr
mailing list