Posted on 2006-04-01
I have a question about how wchar_t works. I understand that wchar_t is either two or four bytes, depending on your system, and allows a much wider range of characters to be stored than would be permitted by char, which is limited to 00000000 to 11111111 (0 to 255).
But I'm trying to figure out exactly how wchar_t stores the data. I tried a test case where I assign a value of È to a wide character variable.
When I ouput the value of the wchar_t, casting it to an int, I see that È is equivalent to 200.
Now, if I use a char* type, and do:
unsigned char* c = (unsigned char*) "È";
I find I am actually assigning two bytes to the character, and indeed strlen(c) will return a value of 2.
So I examine these two bytes individually:
And I get:
Now, my question(s):
1. How does 195 and 136 combine to give me a value of 200?
2. Since it is possible to store a value of 200 in only one byte, why are the values spread out among two bytes here?