I need to rotate for an example x=0XFF for 3 to right.
I cant do that only with >> because that is shifting.
When you want rotate you need to "memory" all bit not to lose such as in case for shifting (i think).
So that is not the same.
when I write that code in interrupt rutine i have problem with execution...
Code:
if (++counter=20) { //i have error c213 : left side of asn-op not an lvalue THAT ERROR SHOWS THIS LINE OF CODE
shiftbits = 3;
while(shiftbits--)
{
if (x & 0x1) // Should have been bit wise!!!
{
x>>= 1;
x+=128;
display=x;
}
else
x>>=1;
}
counter=0; }
}
i have error c213 : left side of asn-op not an lvalue
Ah!! Remember that 8051 has limited "bit access" memory!!
if NOT ( pre increment counter) +2 .... Will never be true unless it started out negative..
Assume counter = 1.....
pre increment counter (before evaluation ) counter = 2
counter += 2 counter now contains 4 ....
if NOT.... well!! the only time this will be true is if the count was -3 to start with
Hi Mike,
To complicate things further there is rotate and rotate through carry. This is my undersanding of "rotate". (Right) Bit 7 to bit 6 and so on. Bit 0 to bit 7. A rotate through carry is carry bit to bit 7, bit 7 to bit 6 and so on bit 0 to carry bit.
You have to be careful when shifting signed integers. Arithmetic shift to the right add 1's instead of zeros to the left. I edited the code to cast right shift to unsigned.
You have to be careful when shifting signed integers. Arithmetic shift to the right add 1's instead of zeros to the left. I edited the code to cast right shift to unsigned.