Re: Regarding Left shift operator in embedded processor
From: Tim Wescott (tim_at_wescottnospamdesign.com)
Date: 01/14/05
- Next message: Tim Wescott: "Re: What about the motorola microcontroller?"
- Previous message: Tim Wescott: "Re: Building a DC Power Supply for ATX system"
- Maybe in reply to: Ravi kumar.N: "Regarding Left shift operator in embedded processor"
- Next in thread: toby: "Re: Regarding Left shift operator in embedded processor"
- Reply: toby: "Re: Regarding Left shift operator in embedded processor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Fri, 14 Jan 2005 07:59:04 -0800
Hans-Bernhard Broeker wrote:
> Ravi kumar.N <ravikumar.n@sunlux-india.com> wrote:
>
>
>> "Is it valid to shift a byte value by an 8-bit".
>
>
> Not for the vast majority of meanings the word "valid" in that
> sentence could have, no.
>
> On the typical platform, shifting a byte left by 8 yields a constant
> zero --- if that was what you wanted, you could just have spelled out
> that zero.
>
> The correct way of doing what you wanted would be (with some extraneous
> parentheses
>
> (((unsigned short) a) <<8) | b
>
> I.e. turn a into a 2-byte value *before* you shift.
>
Unless you want to shift a byte left by a variable amount, and zero is
the correct answer if you're shifting by eight. Then you either need to
hope that your platform just uses a shift-left instruction (giving you
zero), or you have to add a test (consuming expensive clock ticks).
-- Tim Wescott Wescott Design Services http://www.wescottdesign.com
- Next message: Tim Wescott: "Re: What about the motorola microcontroller?"
- Previous message: Tim Wescott: "Re: Building a DC Power Supply for ATX system"
- Maybe in reply to: Ravi kumar.N: "Regarding Left shift operator in embedded processor"
- Next in thread: toby: "Re: Regarding Left shift operator in embedded processor"
- Reply: toby: "Re: Regarding Left shift operator in embedded processor"
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|