View Single Post
  #9   Spotlight this post!  
Unread 10-01-2007, 22:08
darist darist is offline
Registered User
AKA: David Aristizabal
no team
Team Role: Mentor
 
Join Date: Jan 2006
Rookie Year: 2006
Location: Newark, NJ
Posts: 36
darist is an unknown quantity at this point
Re: Thanks for all your help...and a question

Quote:
Originally Posted by Kevin Sevcik View Post
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!