Or in fact if your results may be > 16 bits you can use uint32_t result = param1 - param2 then check if > 65535 and deal with it. etc > To: avr-chat@yahoogroups.com > From: catalin_cluj@hotmail.com > Date: Fri, 2 Sep 2011 16:38:28 -0600 > Subject: RE: [AVR-Chat] Calculate signed and unsigned > > > I would use > uint16_t instead of unsigned int. > int16_t instead of int. > > > Cast to (uint16_t) > > > I never know what an int size is :-) > > > Your operations might result in numbers greater than 16 bits; must make sure you deal with that. > > > Cat > > > To: AVR-Chat@yahoogroups.com > > From: djantoxa@rambler.ru > > Date: Sat, 3 Sep 2011 01:10:58 +0300 > > Subject: [AVR-Chat] Calculate signed and unsigned > > > > Hello! > > > > I using AtMega32A, AVRStudio 4.18SP3 and WinAVR 2011. > > > > unsigned int param1; > > signed int param2; ( > > unsigned int param3; > > > > OCR1B = (unsigned int)(param1 - param2); > > OCR1A = (unsigned int)(param1 - param2 - param3); > > > > I do not get the correct result. How to calculate signed and unsigned variables? > > > > -- > > Best regards, > > Roman Antoshchenkov > > > > Kharkiv > > Ukraine > > > > [Non-text portions of this message have been removed] > > > > ------------------------------------ > > Yahoo! Groups Links > > > [Non-text portions of this message have been removed]
Message
RE: [AVR-Chat] Calculate signed and unsigned
2011-09-02 by Cat C
Attachments
- No local attachments were found for this message.