[Tinyos-help] Re: weird problem with arithmetic shift left
Matthew Dorsch
matthew.dorsch at baesystems.com
Wed Mar 30 12:08:35 PST 2005
Thierry,
I'm pretty sure the problem is that you are left-shifting an 8 bit
value. Try this:
> micReading = m->data[11];
>
> micReading = (micReading << 8) + m->data[10];
This way, when the left shift occurs, there's room for those bits
to be shifted into.
Matt
>Message: 7
>Date: Wed, 30 Mar 2005 11:04:42 -0800 (PST)
>From: Thierry <tools4the at yahoo.com>
>Subject: [Tinyos-help] weird problem with arithmetic shift left
> operation in NesC
>To: tinyos-help at Millennium.Berkeley.EDu
>Message-ID: <20050330190443.6187.qmail at web30210.mail.mud.yahoo.com>
>Content-Type: text/plain; charset=us-ascii
>
>
>Hi all,
>
>I encountered the following weird problem.
>I need to retrieve the 16-bit reading at m->data[10] &
>m->data[11].
>That is, suppose m->data[10] = 0xAC and
>m->data[11]=0x1, then I want to get micReading =
>0x1AC.
>
>
>The following code always gives me the value of only
>m->data[10] (i.e. micReading = 0xAC) even though if I
>comment out the line "micReading = micReading +
>m->data[MIC];", I can clearly see that micReading =
>0x100 (256 decimal).
>
>
> event TOS_MsgPtr RadioReceive.receive(TOS_MsgPtr m) {
> uint8_t i, j;
> uint16_t micReading, tmp;
>
> micReading = (m->data[11] << 8);
>
> micReading = micReading + m->data[10];
> ....
>
>
>I appreciate your help!
More information about the Tinyos-help
mailing list