Question

In: Computer Science

2. Write a program that asks for hexadecimal number and converts it to decimal. Then change...

2. Write a program that asks for hexadecimal number and converts it to decimal. Then change it to convert an octal number to decimal in perl language.

Solutions

Expert Solution

Program to convert an hexadecimal to decimal is as following:

print "Enter a number in Hexadecimal format(i.e., in 0x.. format): ";
$num = <STDIN>;
chomp $num; #removes new line character from input
exit unless defined $num;
$num = hex($num) if $num =~ /^0/;
printf "Number in decimal: %d \n", $num;

Sample output to above program is as following:

Code to convert Octal to decimal is as following:

print "Enter a number in Octal format( i.e, 0...format): ";
$num = <STDIN>;
chomp $num; #removes new line character from input
exit unless defined $num;
$num = oct($num) if $num =~ /^0/; 
printf "Number in decimal: %d \n", $num;

Sample output to above program is as following:

Note - if any doubt/query, do ask in comment section


Related Solutions

Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are...
Write a program in C++ that converts decimal numbers to binary, hexadecimal, and BCD. You are not allowed to use library functions for conversion. The output should look exactly as follows: DECIMAL      BINARY                     HEXDECIMAL                      BCD 0                      0000 0000                   00                                            0000 0000 0000 1                      0000 0001                   01                                            0000 0000 0001 2                      0000 0010                   02                                            0000 0000 0010 .                       .                                   .                                               . .                       .                                   .                                               . 255                  1111 1111                   FF                                            0010 0101 0101
Exercise 1: Write a program that converts a number entered in Roman numerals to decimal. Your...
Exercise 1: Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class, say, Roman. An object of type Roman should do the following: Store the number as a Roman numeral. Convert and store the number into decimal. Print the number as a Roman numeral or decimal number as requested by the user. The decimal values of the Roman numerals are: M 1000 D 500 C 100 L 50 X 10...
c ++ program that converts from any base to a decimal number
c ++ program that converts from any base to a decimal number
3. Write a java method that accepts a binary number and converts it to decimal then...
3. Write a java method that accepts a binary number and converts it to decimal then display the result. For Example: (110)2 = (6)10 (2 2 *1)+ (21 *1) + (20*0) = 6 Additional task: write a method that accepts a decimal and converts it to binary. i need to solve it as soon as and i will upvote you directly
Write Java program that asks a user to input a letter, converts the user input to...
Write Java program that asks a user to input a letter, converts the user input to uppercase if the user types the letter in lowercase, and based on the letter the user the user enters, display a message showing the number that matches the letter entered. For letters A or B or C display 2 For letter D or E or F display 3 For letter G or H or I display 4 For letter J or K or L...
2. Write a program C++ that asks the user for a number (not necessary to force...
2. Write a program C++ that asks the user for a number (not necessary to force any particular requirements). Write a function with the following signature: double square(double x) that returns the square of the user's number (x * x). 3. Write a C++ program that asks the user for an integer. Write a function that returns 1 of the number is even, and 0 if the number is odd. Use this function signature: int isEven(int x). 4. Write a...
Write a program that accepts a number of minutes and converts it both to hours and...
Write a program that accepts a number of minutes and converts it both to hours and days. For example, 6000 minutes is 100.0 hours or 4.166666666666667 days. (I currently have what is below) import java.util.Scanner; public class MinutesConversion { public static void main(String[] args) { Scanner sc = new Scanner(System.in); int numOfMinutes = sc.nextInt(); double hour = numOfMinutes/60.00; double days = (hour/24); System.out.println(numOfMinutes + " minutes is " + hour + " hours or " + days + " days.");...
Write a program that accepts a number of minutes and converts it to days and hours....
Write a program that accepts a number of minutes and converts it to days and hours. For example, 6000 minutes represents 4 days and 4 hours. Be sure to provide proper exception handling for non-numeric values and for negative values. Save the file as  MinuteConversionWithExceptionHandling.java
Program that does conversions (i.e. decimal to hexadecimal, binary to decimal) but needs to have a...
Program that does conversions (i.e. decimal to hexadecimal, binary to decimal) but needs to have a drop down menu to give you the option to choose with conversion you want to go from and convert into (JOptionPane). Cannot use the conversion tool that is built-in Java. Need to use equations or some sort. Please include comments on what is happening to understand.
Write a program in java that asks the name of the buyer and the number of...
Write a program in java that asks the name of the buyer and the number of shares bought. Your program must then calculate and display the following. sold stock/shares to the general public at the rate of $24.89 per share. Theres a 2 percent (2%) commission for the transaction. Outputs need Amount paid for buying the stock ($) Amount paid for the commission ($) Total amount ($)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT