Perl Programming/Keywords/hex

Previous: grep Keywords Next: if

The hex keywordEdit

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

SyntaxEdit

  hex EXPRESSION

ExamplesEdit

 
  $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