Hi, this "problem" is not related to MSP430, nesC or TinyOS. Rather it's related to the C standard. The point 4 from section 6.5.3.3 of the C99 standard reads:
"The result of the ~ operator is the bitwise complement of its (promoted) operand (that is, each bit in the result is set if and only if the corresponding bit in the converted operand is not set). The integer promotions are performed on the operand, and the result has the promoted type. If the promoted type is an unsigned type, the expression ~E is equivalent to the maximum value representable in that type minus E." (I'm unable to find the C89 standard at this moment, but it says pretty much the same things). Therefore if you do: ~a the type is promoted to signed int, and its value is -6. Since 255-a = 250, the results are different and your comparison returns false. Regards. -- Giuseppe Cardone On Thu, Apr 22, 2010 at 5:46 PM, Juchli Bruno HSLU T&A <[email protected]> wrote: > > ---------- Forwarded message ---------- > From: Juchli Bruno HSLU T&A <[email protected]> > To: "[email protected]" > <[email protected]> > Date: Thu, 22 Apr 2010 17:46:45 +0200 > Subject: Bitwise Not (Complement) Operator @ msp430 / nesc 1.3.1 > Dear All, > > i've had some trouble debugging my TinyOS 2.1.1 application today. I've had > some code that essentially was the same as: > > uint8_t a = 5; > > what struck me, was that the following returned FALSE: > > (~a == (255-a)) > > > { Note: > b00000101 = 5 > b11111010 = ~5 = 250 = (255-5) > } > > Did i miss something or is this a (un-)known problem? > > I ended up using (255-b) instead of ~b. > > regards, > Bruno Juchli _______________________________________________ Tinyos-help mailing list [email protected] https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
