There are many questions related to this but they answer conversion of char* to unsigned char*. What I want to ask is conversion of char to unsigned char :
If I cast ( C-style or static-cast ) a char to an unsigned char like :
char c = 'A' ; unsigned char uc = ( unsigned char ) c ;
Can the integral value of c
change during the cast ? As char is signed or unsigned, is implementation defined, so wherever it is signed , is it possible that the cast would change the integral value of the character ?
My Primary concern is for positive values. If I cast the 'above' way, is there a possibility of the values being changed?
Since C++14, char
if signed
must be 2's complement.
Therefore the cast from signed char
to unsigned char
and vice-versa cannot change the underlying bit pattern.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.