Perl | hex Function

The hex function in Perl converts the given hexadecimal number ( of base 16 ) into its equivalent decimal number ( of base 10 ).

Syntax: hex number

Parameters:
number: hexadecimal number to be converted

Returns: equivalent decimal number of the given hexadecimal number.

Example 1:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl
  
# Initialising some hexadecimal values for
# the parameter of the hex function
$A = "A";
$B = "B";
$C = "1A";
$D = "2C";
  
# Calling the hex function
$E = hex $A;
$F = hex $B;
$G = hex $C;
$H = hex $D;
  
# Getting the equivalent decimal number
# of the given hexadecimal number
print "$E\n";
print "$F\n";
print "$G\n";
print "$H\n";

chevron_right



Output:

10
11
26
44

Example 2:

filter_none

edit
close

play_arrow

link
brightness_4
code

#!/usr/bin/perl
  
# Initialising some hexadecimal values and
# Calling the hex function
$A = hex D;
$B = hex af;
$C = hex AF;
$D = hex BF;
  
# Getting the equivalent decimal number
# of the given hexadecimal number
print "$A\n";
print "$B\n";
print "$C\n";
print "$D\n";

chevron_right


Output :

13
175
175
191


My Personal Notes arrow_drop_up

Check out this Author's contributed articles.

If you like GeeksforGeeks and would like to contribute, you can also write an article using contribute.geeksforgeeks.org or mail your article to contribute@geeksforgeeks.org. See your article appearing on the GeeksforGeeks main page and help other Geeks.

Please Improve this article if you find anything incorrect by clicking on the "Improve Article" button below.




Article Tags :
Practice Tags :


Be the First to upvote.


Please write to us at contribute@geeksforgeeks.org to report any issue with the above content.