??? 10/21/10 22:35 Read: times |
#179260 - The C Standard Responding to: ???'s previous message |
http://flash-gordon.me.uk/ansi.c.txt
3.3.7 Bitwise shift operators
Syntax shift-expression: additive-expression shift-expression << additive-expression shift-expression >> additive-expression Constraints Each of the operands shall have integral type. Semantics The integral promotions are performed on each of the operands. The type of the result is that of the promoted left operand. If the value of the right operand is negative or is greater than or equal to the width in bits of the promoted left operand, the behavior is undefined. The result of E1 << E2 is E1 left-shifted E2 bit positions; vacated bits are filled with zeros. If E1 has an unsigned type, the value of the result is E1 multiplied by the quantity, 2 raised to the power E2, reduced modulo ULONG_MAX+1 if E1 has type unsigned long, UINT_MAX+1 otherwise. (The constants ULONG_MAX and UINT_MAX are defined in the header <limits.h> .) The result of E1 >> E2 is E1 right-shifted E2 bit positions. If E1 has an unsigned type or if E1 has a signed type and a nonnegative value, the value of the result is the integral part of the quotient of E1 divided by the quantity, 2 raised to the power E2 . If E1 has a signed type and a negative value, the resulting value is implementation-defined. The sad part is that if you did use the other method of defining like the Keil example code, that would not help if "i" was defined as just char instead of unsigned char. |