Re: Regarding Left shift operator in embedded processor

From: Tim Wescott (tim_at_wescottnospamdesign.com)
Date: 01/14/05


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


Relevant Pages

  • Re: How to describe negative error?
    ... Any movement away from zero is an increase in error value. ... shifting device; boys become girls and girls become boys. ...
    (alt.usage.english)
  • Re: Twos complement integer divided by Powers of 2 question
    ... When a signed positive integer X divided by pow, the result is shifting k bits to right and putting w-k bits of 0 from the most significant bits. ... However, the result of the integer division -3/2 is not -2, but -1: Integer division discards the fractional part of the "true" quotient, ... For even X there's nothing to truncate and you'll get the same answer either way, and for positive X zero is in the same direction as minus infinity. ...
    (comp.lang.c)
  • synthesis intelligence of quartus regarding range of values
    ... I am shifting with 10 Bits and fill the rest with zero: ... whereby the vector of the result (devider out) has of course 48 bits. ... Currently I am cutting away the first bits, which will always be zero. ... s there anything more, I can do, to keep the design small? ...
    (comp.arch.fpga)
  • Re: stationary process pass through an LTI system still stationary?
    ... but if you have a system that holds its output at zero until ... _is_ time invariant then you must have a signal that is zero for t < 0 ... Now, granted, if you have an unstable or metastable system your output ... Wescott Design Services ...
    (sci.math)
  • Re: zero the last 13 bits of an unsigned long number
    ... zero the 13 LSB bits of this number. ... I also thought of right shifting the number by 13 bits and ... It's conceivable, I suppose, that you might save a femtogrunt by twiddling ...
    (comp.lang.c)