perl-5.38.0
hex EXPR
hex

Interprets EXPR as a hex string and returns the corresponding numeric value. If EXPR is omitted, uses $_.

EXPR を 16 進数の文字列と解釈して、対応する数値を返します。 EXPR が省略されると、$_ を使います。

    print hex '0xAf'; # prints '175'
    print hex 'aF';   # same
    $valid_input =~ /\A(?:0?[xX])?(?:_?[0-9a-fA-F])*\z/

A hex string consists of hex digits and an optional 0x or x prefix. Each hex digit may be preceded by a single underscore, which will be ignored. Any other character triggers a warning and causes the rest of the string to be ignored (even leading whitespace, unlike oct). Only integers can be represented, and integer overflow triggers a warning.

16 進文字列は 16 進数と、オプションの 0x または x 接頭辞からなります。 それぞれの 16 進数は一つの下線を前に置くことができ、これは無視されます。 その他の文字は警告を引き起こし、(例え先頭の空白でも、oct と 異なり)文字列の残りの部分は無視されます。 整数のみを表現でき、整数オーバーフローは警告を引き起こします。

To convert strings that might start with any of 0, 0x, or 0b, see oct. To present something as hex, look into printf, sprintf, and unpack.

0, 0x, 0b のいずれかで始まるかもしれない文字列を変換するには、 oct を参照してください。 何かを 16 進で表現したい場合は、printf, sprintf, unpack を 参照してください。