以下の内容はhttps://yohhoy.hatenadiary.jp/entry/20241022/p1より取得しました。


16進文字から数値への変換: ch - 'a' + 10

プログラミング言語Cの次期仕様C2yでは、16進数表記で用いられるアルファベット文字範囲'a''f'および'A''F'について文字コードの連続性保証が明文化される。

この文字コード範囲での連続性保証は、ラテンアルファベット26文字 A~Z / a~z が連続配置されるASCII互換文字コードUnicodeだけでなく、EBCDIC文字コードにおいても成立する*1

int ch = /*...*/;
assert(isxdigit(ch));  // chは任意の16進文字

int n;
if ('0' <= ch && ch <= '9') {
  n = ch - '0';  // 0...9
} else if ('a' <= ch && ch <= 'f') {
  n = ch - 'a' + 10;  // a...f
} else {
  n = ch - 'A' + 10;  // A...F
}

C2y WD N3301 5.3.1/p3-5, Annex M.2より一部引用。

3 (snip) In both the source and execution basic character sets, the value of each character after 0 in the preceding list of decimal digits shall be one greater than the value of the previous. (snip)
4 The value of each character after a, up to and including f, in the prior specified list of lowercase letters shall be one greater than the value of the previous.
5 The value of each character after A, up to and including F, in the prior specified list of uppercase letters, shall be one greater than the value of the previous.

Uppercase characters "A" through "F" ('A' through 'F') and lowercase characters "a" through "f" ('a' through 'f'), colloquially known as the "hexidecimal digits", are now guaranteed to be sequential.

関連URL

*1:EBCDICではアルファベット文字コードの割当が A~I / J~R / S~Z の3ブロックに分かれている。数値文字コード 0~9 は連続配置される。




以上の内容はhttps://yohhoy.hatenadiary.jp/entry/20241022/p1より取得しました。
このページはhttp://font.textar.tv/のウェブフォントを使用してます

不具合報告/要望等はこちらへお願いします。
モバイルやる夫Viewer Ver0.14