Microchip Technology XC8 Standard Compiler (Workstation) SW006021-1 SW006021-1 User Manual

Product codes
SW006021-1
Page of 518
Common C Interface
 2012 Microchip Technology Inc.
DS52053A-page 21
2.4.9
Integer conversion
When converting an integer type to a signed integer of insufficient size, the original 
value is truncated from the most-significant bit to accommodate the target size.
2.4.9.1
EXAMPLE
The following shows an assignment of a value that will be truncated.
signed char destination;
unsigned int source = 0x12FE;
destination = source;
Under the CCI, the value of destination after the alignment will be -2 (i.e., the bit 
pattern 0xFE).
2.4.9.2
DIFFERENCES
All compilers have performed integer conversion in an identical fashion to that 
described in this section.
2.4.9.3
MIGRATION TO THE CCI
No action required.
2.4.10
Bit-wise Operations on Signed Values
Bitwise operations on signed values act on the two’s complement representation, 
including the sign bit. See also Section 2.4.11 “Right-shifting Signed Values”.
2.4.10.1
EXAMPLE
The following shows an example of a negative quantity involved in a bitwise AND oper-
ation.
signed char output, input = -13;
output = input & 0x7E;
Under the CCI, the value of output after the assignment will be 0x72.
2.4.10.2
DIFFERENCES
All compilers have performed bitwise operations in an identical fashion to that 
described in this section.
2.4.10.3
MIGRATION TO THE CCI
No action required.
2.4.11
Right-shifting Signed Values
Right-shifting a signed value will involve sign extension. This will preserve the sign of 
the original value.
2.4.11.1
EXAMPLE
The following shows an example of a negative quantity involved in a bitwise AND 
operation.
signed char input, output = -13;
output = input >> 3;
Under the CCI, the value of output after the assignment will be -2 (i.e., the bit pattern 
0xFE).