Are digits represented in sequence in all text encodings?

后端 未结 5 1834
甜味超标
甜味超标 2020-12-21 17:05

This question is language agnostic but is inspired by these c/c++ questions.

How to convert a single char into an int

Char to int conversion in C

Is

5条回答
  •  不知归路
    2020-12-21 18:05

    According to K&R ANSI C it is.

    Excerpt:

    ..."This particular program relies on the properties of the character representation of the digits. For example, the test

    if (c >= '0' && c <= '9') ...

    determines whether the character in c is a digit. If it is, the numeric value of that digit is

    c - '0'

    This works only if '0', '1', ..., '9' have consecutive increasing values. Fortunately, this is true for all character sets...."

提交回复
热议问题