Hi Ram,
What do you mean by "displayed in hex"? Are you "displaying" the
variable somewhere? Using printf? Using a debugger to probe the internal
memory?
In your example, strength is a uint16_t. This means it's a 16-bit binary
number on the memory, just like anything else that the memory stores.
You can think of it in any base you like, but it's still binary in the end.
The only way where things become more complicated is if the number is
stored as an ASCII string. In that case, the value of each char in the
string (for example, '3') has to be converted to the binary
representation of that number (3 = '3' - '0'), then everything needs to
be put together depending on what the original base was (decimal, hex,
etc). This *does not* seem to be the case for you.
So to do the one's complement, you just do a bitwise NOT, as someone
else proposed:
ones_complement = ~strength;
In your code, it seems you're trying to do two things at the same time.
You do the one's complement (you do it by XORing with 11111111, which is
the same as taking the NOT as shown above), and you split the strength
into two bytes, using little endian format. So, which one is your
question really about? The one's complement part? Or the type-casting part?
- Thiago
ram kishore wrote:
> Hi,
> I tried #include <stdio.h>,but in vain.
> example code:
> Msg->strength(rssi) is uint16_t variable which is by default displayed
> in hex like shown below:
> ReceivedMsg->data[0] = Msg->strength & 0xFF;(MSB)
> ReceivedMsg->data[1] = Msg->strength >>8; (LSB)
>
> I have to get the 1's complement of Msg->strength.and then convert it
> into decimal.I tried like this.
>
> ReceivedMsg->data[0] = (Msg->strength & 0xFF) ^ 0xFF;
> ReceivedMsg->data[1] = (Msg->strength >>8) ^ 0xFF;
>
> I get the 1's complement but i can't get its decimal
> equivalent.Typecasting didnt work.
>
> Many Thanks,
> kishore
>
>
> On Fri, May 23, 2008 at 6:32 PM, Urs Hunkeler <[EMAIL PROTECTED]> wrote:
>
> Hi,
>
> For the include statement, try:
>
> #include <stdio.h>
>
> The complement operator or the bit-wise XOR operator both should
> work directly with integers. Can you provide us with a short
> example of code that you would like to use?
>
> Cheers,
> Urs
>
> ram kishore wrote:
>
> Hi,
>
> I added #include stdio.h as below to configuration file:
>
> #include stdio.h
> configuration TOSBase {
> }
> implementation {
> components Main, TOSBaseM, RadioCRCPacket as Comm, FramerM, UART,
> LedsC;........
> //some lines
> }
> I get the following error:
> TOSBase.nc:38:10: #include expects "FILENAME" or <FILENAME>
> <commandline>: failed to preprocess TOSBase.nc
>
> Somehow, I got the one's compliment using XOR operator (as said by
> Hunkeler).But how can i convert into integer?
> Is there any pre-defind C function? Or I have to write program
> for that
> conversion?
>
> Many regards,
> Kishore
>
> On Thu, May 22, 2008 at 9:06 PM, Michael Schippling
> <[EMAIL PROTECTED] <mailto:[EMAIL PROTECTED]>>
> wrote:
>
> ones-compliment is negation, c.f.:
> http://www.cis.cau.edu/~mititi/cis472/Binnum/tsld005.htm
>
> <http://www.cis.cau.edu/%7Emititi/cis472/Binnum/tsld005.htm><http://www.cis.cau.edu/%7Emititi/cis472/Binnum/tsld005.htm>
>
>
>
> I believe that you #include studio.h in exactly that way,
> however you may be disappointed as to how many of the
> functions are supported under TOS.
>
> MS
>
> ram kishore wrote:
>
> Hi,
> I need to find 1's complement of the incoming hex
> message.How to add
> #include<stdio.h> to my application?
> Is there any alternative way of doing this?
>
> Regards,
> Kishore
>
>
> ------------------------------------------------------------------------
>
> _______________________________________________
> 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