Quote:
Originally Posted by Kevin Sevcik
Question to Alan (or anyone),
I'm under the impression a >>1 instead of a /2 would work there and would (possibly?) be faster. We've tried this in some spots in code before, however, and I think it corrupts signed variables. Do you (or anyone) have any specific knowledge about the >> operator on this PIC? I was sort of hoping that it or some other operator will do a signed >> operation and carry the signed bit.
|
The ">>" in C is the "shift right bitwise" operation. Because of the fact that microprocessors use the binary number system (0s and 1s) a "shift right" results in the same thing as "divide by 2 (but throw away the remainder)."
I was looking throug the MCC18 (Microchip's C compiler) User Guide and found this in Appendix B.4:
Quote:
ANSI C Standard: “The result of a right shift of a negative-valued signed integral type (6.3.7).”
Implementation: The value is shifted as if it were an unsigned integral type of the same size (i.e., the sign bit is not propagated).
|
Sounds to me like the MCC18 compiler does not have a way to make ">>" operate on signed integers.
Good luck!