Saturday, May 31, 2014

Converting Hexadecimal to Decimal

Script

#!/usr/bin/perl

print ("Enter a Hexadecimal number: ");
$hexa_number = <STDIN>;
chop ($hexa_number);
$decimal = hex ($hexa_number);

print ("The decimal equivalent of the Hexadecimal number $hexa_number is: ", $decimal);
print ("\n\n\n");



Execution

Enter a Hexadecimal number: 25
The decimal equivalent of the Hexadecimal number 25 is: 37


Enter a Hexadecimal number: 10
The decimal equivalent of the Hexadecimal number 10 is: 16


Enter a Hexadecimal number: 3A
The decimal equivalent of the Hexadecimal number 3A is: 58


Enter a Hexadecimal number: FE
The decimal equivalent of the Hexadecimal number FE is: 254


Enter a Hexadecimal number: FFFF
The decimal equivalent of the Hexadecimal number FFFF is: 65535


Enter a Hexadecimal number: FEFCFAF2
The decimal equivalent of the Hexadecimal number FEFCFAF2 is: 4277992178


Enter a Hexadecimal number: ABCDEF
The decimal equivalent of the Hexadecimal number ABCDEF is: 11259375





No comments:

Post a Comment