#!/usr/bin/perl
print ("Enter a decimal number: ");
$decimal_number = <STDIN>;
chop ($decimal_number);
$hexa = sprintf("%X", $decimal_number);
$bina = sprintf("%B", $decimal_number);
print ("\nThe Hexadecimal equivalent of the Decimal number $decimal_number is: ", $hexa);
print ("\n\n");
print ("The Binary equivalent of the Decimal number $decimal_number is : ", $bina);
print ("\n\n\n");
Execution
Enter a decimal number: 64
The Hexadecimal equivalent of the Decimal number 64 is: 40
The Binary equivalent of the Decimal number 64 is : 1000000
Enter a decimal number: 255
The Hexadecimal equivalent of the Decimal number 255 is: FF
The Binary equivalent of the Decimal number 255 is : 11111111
Enter a decimal number: 4096
The Hexadecimal equivalent of the Decimal number 4096 is: 1000
The Binary equivalent of the Decimal number 4096 is : 1000000000000
Enter a decimal number: 8191
The Hexadecimal equivalent of the Decimal number 8191 is: 1FFF
The Binary equivalent of the Decimal number 8191 is : 1111111111111
Enter a decimal number: 799
The Hexadecimal equivalent of the Decimal number 799 is: 31F
The Binary equivalent of the Decimal number 799 is : 1100011111
No comments:
Post a Comment