This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

working with right shift operators in C

I am facing a problem in using the right shift operator in C with keil.
The instruction is:for(i=0;i<=8;i++) { j=sum>>i; }
where sum= 32 bit no.
the instruction is not executed if the syntax is as shown above. but if i write a numerical value instead of using the variable name 'sum' then the instruction is easily executed. i need to use the variable name only. how do i fix this problem?

Parents
  • here sum is defined as long int in the code. hence it can have a 32 bit value. but in the present case 'sum' holds a 16 bit value only.
    the problem is:
    the instruction for right shift is not executed if the syntax is as follows:
    for(i=0;i<=8;i++)
    { j=sum>>i;
    } but the instruction is executed if the syntax is as follows:
    for(i=0;i<=8;i++)
    { j=0x0258>>i;
    } i.e. the instruction is not executed if i am using the variable name 'sum' but if i put a numerical value instead of 'sum' then it is easily executed.
    how do i fix this problem?

Reply
  • here sum is defined as long int in the code. hence it can have a 32 bit value. but in the present case 'sum' holds a 16 bit value only.
    the problem is:
    the instruction for right shift is not executed if the syntax is as follows:
    for(i=0;i<=8;i++)
    { j=sum>>i;
    } but the instruction is executed if the syntax is as follows:
    for(i=0;i<=8;i++)
    { j=0x0258>>i;
    } i.e. the instruction is not executed if i am using the variable name 'sum' but if i put a numerical value instead of 'sum' then it is easily executed.
    how do i fix this problem?

Children
No data