Interesting... I wonder if the "a" is not being
reloaded on the second use -- giving (255 - ~a),
or something of that ilk. It would be instructive
to look at the assembly code if you can generate it.
Or try using an intermediate variable
b= ~a;
if( b == (255-a) )
MS
Juchli Bruno HSLU T&A wrote:
> ------------------------------------------------------------------------
>
> Subject:
> Bitwise Not (Complement) Operator @ msp430 / nesc 1.3.1
> From:
> Juchli Bruno HSLU T&A <[email protected]>
> Date:
> Thu, 22 Apr 2010 17:46:45 +0200
> To:
> "[email protected]" <[email protected]>
>
> To:
> "[email protected]" <[email protected]>
>
>
> 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
>
> PS: this is an excerpt from the actual code:
>
> uint8_t rxLength;
>
> async event void UartStream.receivedByte( uint8_t byte ) {
> (...)
> case STATE_WAIT_FOR_LEN:
> rxLength = byte;
> mReceiveState = STATE_WAIT_FOR_NLEN;
> break;
> case STATE_WAIT_FOR_NLEN:
> //if (byte == ~rxLength) { //not working
> if ((255-byte) == rxLength) { //working just
> fine
> mReceiveState = STATE_WAIT_FOR_MESSAGE;
> rxBytesToRead = rxLength + 4; //+
> address + contentType + CRC16
> messageBuffer[0] = rxLength;
> rxBufferBegin = 1;
> } else {
> mReceiveState = STATE_WAIT_FOR_ALERT;
> }
> break;
> (...)
> }
>
> ________________________________________
> Bruno Juchli
>
> University of Applied Sciences Lucerne, Switzerland
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> Tinyos-help mailing list
> [email protected]
> https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help
_______________________________________________
Tinyos-help mailing list
[email protected]
https://www.millennium.berkeley.edu/cgi-bin/mailman/listinfo/tinyos-help