문제

I am trying to make a shift operation to compute y=11*x+7/16*x for 0 < x<2000. My code is as follows: Did I do the shift operation correctly? Also, what does the interval 0 < x<2000 mean? Doesn't x have to be equal to a set constant?

#include <msp430.h> 
int x,y;
void main(void)
{
    y=(x<<3+x<<1+x)+(x<<2+x<<1+x)>>4;
}
도움이 되었습니까?

해결책

Notes:

  1. The interval 0 < x < 2000 probably means that you have to iterate on every integer value between 0 and 2000.

  2. From your code, it appears that you want y=11*x+7*x/16 and not y=11*x+7/16*x as stated in your question.

  3. You should add parentheses on every Shift operation, in order to make sure that it is not preceded by an Addition operation.

  4. You can add a printout after every iteration in order to make sure that it works correctly.

See sample code below:

void main(void)
{
    int x,y;
    for (x=1; x<=1999; x++)
    {
        y = ((x<<3)+(x<<1)+x)+(((x<<2)+(x<<1)+x)>>4);
        printf("x=%d y=%d\n",x,y);
    }
}
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top