Saturday, May 31, 2014

Converting Hexadecimal to Binary

Script

#!/usr/bin/perl

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

$bina = sprintf("%B", $tempo);

print ("\nThe Binary equivalent of the Hexadecimal number $hexa_number is:  ", $bina);
print ("\n\n\n");


Execution

Enter a Hexadecimal number: F

The Binary equivalent of the Hexadecimal number F is:  1111



Enter a Hexadecimal number: FF

The Binary equivalent of the Hexadecimal number FF is:  11111111



Enter a Hexadecimal number: 57

The Binary equivalent of the Hexadecimal number 57 is:  1010111



Enter a Hexadecimal number: CA

The Binary equivalent of the Hexadecimal number CA is:  11001010


Enter a Hexadecimal number: 3DEF

The Binary equivalent of the Hexadecimal number 3DEF is:  11110111101111

No comments:

Post a Comment