Multibyte Integers Variables in C

ascii, c

Solution

These are:

not strings!

multibyte integers, of which the value is implementation-defined, but it is usually calculated using this formula:

`integer value of 1st character multiplied by (2 << CHAR_BITS) + integer value of 2nd character`

So, assuming your C locale uses ASCII and you have 8-bit bytes, `'aA'` becomes

97 * 256 + 65

which is 24897.

Multicharacter literals are of type `int`.

Problem

I'd like to know, how to calculate integer values of strings in single quotes `' '`. My sample code is: ``` #include <stdio.h> int main() { int c = 'aA'; int d = 'Aa'; printf( "%d %d" , c, d); return 0; } ``` And the output is: ``` 24897 16737 ``` What are those numbers? Is there any formula to calculate them ?

Original source

Related problems