posted 18 years ago
Hello Bimal,
Thanks for the quick response. I was about to post my findings:
Actually, one thing I missed was that, a char is a signed 16 bit INTEGER literal under the "hood" -- whatever hood meant :-)
So,
char a = 98;
is the same as
char b = (char)65634; // becausee 65634 = 65536 + 98, where 65536 = 2^16.
OR
char c = (char)-98;
is the same as
char d = 65438; //because 65438 = 65536 (which is 2^16) - 98.
So there's a roll over thing going on if the number assigned to a char exceeds 2^16-1 or is less than -2^16, but of course, there has to be a casting to (char), AND, the number should not exceed 2^31-1 or be less than -2^31.
Thanks,
-Vijay