< Perl Programming < Keywords

The hex keyword

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

Syntax

  hex EXPRESSION

Examples

  $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.

This article is issued from Wikibooks. The text is licensed under Creative Commons - Attribution - Sharealike. Additional terms may apply for the media files.