Jump to content

Perl Programming/Keywords/hex

From Wikibooks, open books for an open world
Previous: grep Keywords Next: if

The hex keyword

[edit | edit source]

hex interprets the EXPRESSION that follows as a hexadecimal string and returns it as such.

Syntax

[edit | edit source]
  hex EXPRESSION

Examples

[edit | edit source]
  $name = "Anton";
  print "'" . $name . "', " . hex $name . ",\n\n\n";
  $value = "AF";
  print $value . ", " . hex $value . "\n";
'Anton', 10AF, 175

The result of hex is the value of the hexadecimal string. $name starts with 'A', which is equal to the hexadecimal digit 0xA. As the rest cannot be interpreted as a number, it is omitted – same for all carriage returns. The hex value of $value is numerically 175, which is returned. Again, the carriage return \n is omitted, as it does not convert to a hexadecimal digit.


Previous: grep Keywords Next: if