Answered step by step
Verified Expert Solution
Link Copied!

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

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

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 (See Sample Output for examples) Sample Output Example of testing your program as follows (your submitted program name is Lab04.java) java Lab4_mgonzales183 1492 11111110 The conversion of positive decimal number 1492 to unsigned binary is 10111010100 The conversion of unsigned binary number 11111110 to positive decimal is 254 java Lab4 2016 11100010 The conversion of positive decimal number 2016 to unsigned binary is 11111100000 The conversion of unsigned binary number 11100010 to positive integer is 226

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Practical Azure SQL Database For Modern Developers Building Applications In The Microsoft Cloud

Authors: Davide Mauri, Silvano Coriani, Anna Hoffma, Sanjay Mishra, Jovan Popovic

1st Edition

1484263693, 978-1484263693

More Books

Students also viewed these Databases questions

Question

What is Stark Law and how does it apply to healthcare?

Answered: 1 week ago

Question

How do Excel Pivot Tables handle data from non OLAP databases?

Answered: 1 week ago