简体   繁体   中英

How is é bitwise shifted to a E in C++?

Hello I having trouble understanding this and how for example it take an accent char like é and converts it E9 . I could be missing something i get that it bit-shifts right 4. é = 11101000 and E = 01000101 shifting 4 doesn't make E right?

static const char *digits = "0123456789ABCDEF";
unsigned char ch;
*dest++ = digits[(ch >> 4) & 0x0F];//this returns E
*dest++ = digits[ch & 0x0F];//this returns 9

The code doesn't convert é to E9 - it converts an 8-bit number to its hexadecimal representation, in four-bit pieces ("nybbles").

digits[(ch >> 4) & 0x0F] is the digit that represents the high nybble, and digits[ch & 0x0F] is the digit that represents the low nybble.

If you see é become E9 , it's because é has the value 233 in your character encoding.

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.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM