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
  • the code is for adding 15 nos and then finding the average. the problem i am facing is:
    if the synax is as follows:

    j=sum>>8;
    


    the instruction is not executed.
    but if i put a numerical value instead of the variable name sum then the instruction is easily executed.
    Similarly if the syntax is as follows:

    avg=sum / 0x0f;
    


    the above instruction is not executed using the variable name 'sum'.
    Since i need to use only variable names in the code what can i do about the above mentioned problems.

Reply
  • the code is for adding 15 nos and then finding the average. the problem i am facing is:
    if the synax is as follows:

    j=sum>>8;
    


    the instruction is not executed.
    but if i put a numerical value instead of the variable name sum then the instruction is easily executed.
    Similarly if the syntax is as follows:

    avg=sum / 0x0f;
    


    the above instruction is not executed using the variable name 'sum'.
    Since i need to use only variable names in the code what can i do about the above mentioned problems.

Children