-3

In many languages such as Java, C, or C++, char can be converted to int easily. For example the char 'A' is the int 65 and so on. What encoding is that?

Govind Parmar
  • 20,656
  • 7
  • 53
  • 85
Katedral Pillon
  • 14,534
  • 25
  • 99
  • 199
  • What are you trying to ask? Why 'A' is equal to 65? Because ASCII. – DeiDei Jan 25 '17 at 00:50
  • That's ASCII, and also UTF-8. –  Jan 25 '17 at 00:50
  • 1
    Encoding is a different concept which is not related to int char topic. What do you want to know exactly ? – akash Jan 25 '17 at 00:50
  • 1
    In C language `'A'` already is an `int`. Please try `printf("%zu\n", sizeof('A'))` – Weather Vane Jan 25 '17 at 00:51
  • hmmm. So what is the relationship between ASCII and encoding such as Unicode? I am at a lost. – Katedral Pillon Jan 25 '17 at 00:51
  • ASCII is a very limited encoding that is a subset of many other encodings like UTF-8. – Louis Wasserman Jan 25 '17 at 00:52
  • It's a different encoding. Also see EBCDIC, PETSCII, Baudot, etc. What's the difference between Polish and Italian? They are both languages. – Robert Columbia Jan 25 '17 at 00:53
  • 1
    [What's the difference between ASCII and Unicode?](http://stackoverflow.com/q/19212306/327083) – J... Jan 25 '17 at 00:55
  • 1
    [What is ANSI format?](http://stackoverflow.com/q/701882/327083) – J... Jan 25 '17 at 00:56
  • 1
    [Unicode, UTF, ASCII, ANSI format differences](http://stackoverflow.com/q/700187/327083) – J... Jan 25 '17 at 00:56
  • Possible duplicate of [What is character encoding and why should I bother with it](http://stackoverflow.com/questions/10611455/what-is-character-encoding-and-why-should-i-bother-with-it) –  Jan 25 '17 at 01:37
  • Closed, so answering in a comment. Per https://gcc.gnu.org/onlinedocs/cpp/Character-sets.html the answer for GCC: the encoding is UTF-8, which reduces to ASCII for the 127 first characters. This is the encoding in which CPP interprets the input file and the `A` character. – Ilia Barahovsky Jan 25 '17 at 14:03

1 Answers1

1

The difference between char and int (apart from their different sizes) is how they're treated in the particular language.

Worth reading on the topic of character encoding: the-absolute-minimum-every-software-developer-absolutely-positively-must-know-about-unicode-and-character-sets-no-excuses

elrat
  • 80
  • 5
  • LOL. I read that before asking the question. I am still at a loss somehow. Sorry it's not coming easy to me. Any chance you can dumb it down for me somehow? Or is it hopeless presently? – Katedral Pillon Jan 25 '17 at 00:57
  • 2
    @KatedralPillon If you read that and it didn't make sense, then perhaps you need to step back and begin your study with how computers work - how memory stores information, how CPUs process that information, and how that information is interpreted. At some level, *everything* is an integer. – J... Jan 25 '17 at 01:02
  • No chance. I'd suggest having a closer look at ASCII - as mentioned in the comments above, and then go ahead with UTF-8, which is commonly used, as it is "compatible" with ASCII, which means any ASCII encoded text is valid UTF-8, but not vice versa. – elrat Jan 25 '17 at 01:03
  • Okay. Clarify this for me: does unicode have 256 items? whereas ASCII has 128? BTW the reading made some sense, it just left me with these particular hiccups. – Katedral Pillon Jan 25 '17 at 01:07
  • @KatedralPillon No, unicode has hundreds of thousands of items. [Characters, Symbols and the Unicode Miracle](https://youtu.be/MijmeoH9LT4?t=21s) – J... Jan 25 '17 at 01:08
  • I thought unicode can be interpreted into hundreds of thousands of different symbols based on the encoding assumed. But that unicode itself had 256 spaces available. So where is the 256 coming from? (I know it's a weird question, but you get the idea. 128 refers to ASCII. what does 256 refer to?) – Katedral Pillon Jan 25 '17 at 01:10
  • @KatedralPillon No, that's ANSI you're thinking of. Time to do some reading. – J... Jan 25 '17 at 01:11
  • @KatedralPillon the three links provided by J... are IMO more readable than this answer's link – Weather Vane Jan 25 '17 at 01:14