Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Objectives 1. To understand the binary representation of unsigned (positive) integer 2. To apply command line arguments 3. To use String class to process the
Objectives 1. To understand the binary representation of unsigned (positive) integer 2. To apply command line arguments 3. To use String class to process the numeric string characters Description Computers store positive integers using binary (base 2) format. That means instead of 10 numerical digits (called decimal or base 10 format), computers only used two digits (either 0 or 1) to represent a positive integer. For example, 1210 will be represented as 11002 in a computer. This assignment requires you to write a java program using command line arguments to acquire any positive integer less than 231 -1 and output its binary representation. Also acquire any unsigned binary (up to 31 bits) from the console and output it decimal representation. Following figure shows how to convert an unsigned decimal to its binary format (this conversation will be further discussed in the class). Quotients Remainders 1.4 92 746 0 3 73 0 186 1 93 0 46 1 23 0 11 1 5 1 2 1 1 0 0 10 11 10 10 10 0 = 149210 Instructions For this assignment, you must use a String class to store a positive decimal and unsigned binary number that are passed in from command line arguments (See Testing and Sample Output sections below to see how the strings are passed in). The main method will receive these command line arguments and pass the String's to the appropriate conversion method. The String that represents the positive decimal will be passed as an argument to the decimalToBinary() method. The String that represents the unsigned binary number will be passed to the binaryToDecimal() method. You must have two conversion methods: 1) decimalToBinary() method, which converts the decimal number (represented as a String) to a binary number (represented as a String) and 2) binaryToDecimal() method, which converts the binary number (represented as a String) to a positive decimal number (represented as a String). After the completion of the conversion, both methods return a String which contain the positive decimal and unsigned binary respectively. Your main() method then output the result to the console. A program template as follow: public static void main(String[] args) { //get the decimalstring and binaryString from command line arguments 1/ here.... String d_s = new String(); // stores the decimal conversion result String b_s = new String(); // stores the binary conversion result b_s = decimalTobinary(decimalString); // decimalString from command argument d_s = binaryTodecimal(binaryString); // binaryString from command argument // your output code here; } public static String decimalToBinary(String decimalstring) { // your positive decimal to unsigned binary code here } public static String binaryToDecimal(String binaryString) { // your unsigned binary to positive decimal code here } Testing I will test your program as follows: javac Lab4_user.java java Lab4_user
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started