Q1. (20 points) Write an application that displays a table of the binary, octal and hexadecimal equivalents of the decimal numbers in the range 1 through 256. Make sure to write logic to ascertain these equivalents of the decimal numbers, not use some library methods. If you aren’t familiar with these number systems, refer the Number systems document provided to you. Include the screenshot of the sample run.
With the java language. Preferably by passing an array to the binary, hex, and octal functions.
/*********************************NumberConversion.java*************************/
public class NumberConversion {
public static void main(String[] args) {
System.out.println("In Binary:");
//You can change array according to you
binary(new int[] { 12, 34, 55, 66,
256 });// calling binary method
System.out.println("In Octal:
");
octal(new int[] { 12, 34, 55, 66,
256 }); // calling octal method
System.out.println("In Hexadecimal:
");
hex((new int[] { 12, 34, 55, 66,
256 })); // calling hex method
}
/*
* binary method to convert decimal values to
binary
*/
public static void binary(int[] nums) {
for (int i = 0; i <
nums.length; i++) {
String s =
"";
int n =
nums[i];
while (nums[i]
> 0) {
s = nums[i] % 2 + s;
nums[i] = nums[i] / 2;
}
System.out.println(n + " --------->" + s);
}
}
/*
* octal method for convert decimal to octal
*/
public static void octal(int[] decimals) {
char octalchars[] = { '0', '1',
'2', '3', '4', '5', '6', '7' };
for (int i = 0; i <
decimals.length; i++) {
int rem;
String octal =
"";
int n =
decimals[i];
while
(decimals[i] > 0) {
rem = decimals[i] % 8;
octal = octalchars[rem] + octal;
decimals[i] = decimals[i] / 8;
}
System.out.println(n + "----------->" + octal);
}
}
/*
* hex method for converting decimal values to
hexadecimal values
*/
public static void hex(int[] nums) {
char hex[] = { '0', '1', '2',
'3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'
};
for (int i = 0; i < nums.length;
i++) {
// to storing
remainder
int rem;
// to storing
result
String hexS =
"";
int n =
nums[i];
while (nums[i]
> 0) {
rem = nums[i] % 16;
hexS = hex[rem] + hexS;
nums[i] = nums[i] / 16;
}
System.out.println(n + "----------->" + hexS);
}
}
}
/*******************************output*************************/
In Binary:
12 --------->1100
34 --------->100010
55 --------->110111
66 --------->1000010
256 --------->100000000
In Octal:
12----------->14
34----------->42
55----------->67
66----------->102
256----------->400
In Hexadecimal:
12----------->C
34----------->22
55----------->37
66----------->42
256----------->100
Please let me know if you have any doubt or modify the answer, Thanks
Q1. (20 points) Write an application that displays a table of the binary, octal and hexadecimal...
Hi, I need help writing a program that reads in data (hex, octal or decimal values) from an input file and outputs the values in to another base form (hex, octal,decimal) one line at a time depending on the formatting characters provided by the input file. I am posting the code requirements below and an example of what theinput file will look like and what should be output by the program. I only need the one .cpp program file. Thanks...
Write a Java program to convert octal (integer) numbers into their decimal number equivalents (exactly the opposite of what you have done in Assignment 4). Make sure that you create a new Project and Java class file for this assignment. Your file should be named “Main.java”. You can read about octal-to-decimal number conversions on wikepedia Assignment 4 is at the bottom Objective Your program should prompt the user to enter a number of no greater than 8 digits. If the...
*In JAVA please* Tasks This lab has two parts: Write a recursive method that converts a decimal number to a different base number system. Print out the results after testing your method on a few different inputs. Task 1 – Recursive Method Create a recursive method that returns a given number converted from base ten to a given other base number system ranging from two to thirty-six. A decimal number, or base ten number, can be expressed in any other...
*Java* Given the attached Question class and quiz text, write a driver program to input the questions from the text file, print each quiz question, input the character for the answer, and, after all questions, report the results. Write a Quiz class for the driver, with a main method. There should be a Scanner field for the input file, a field for the array of Questions (initialized to 100 possible questions), and an int field for the actual number of...