answersLogoWhite

0

import java.util.Scanner;

public class NumberSystem

{

public void displayConversion()

{

Scanner input = new Scanner(System.in);

System.out.printf("%-20s%-20s%-20s%-20s\n", "Decimal",

"Binary", "Octal", "Hexadecimal");

for ( int i = 1; i <= 256; i++ )

{

String binary = Integer.toBinaryString(i);

String octal = Integer.toOctalString(i);

String hexadecimal = Integer.toHexString(i);

System.out.format("%-20d%-20s%-20s%-20s\n", i,

binary, octal, hexadecimal);

}

}

// returns a string representation of the decimal number in binary

public String toBinaryString( int dec )

{

String binary = " ";

while (dec >= 1 )

{

int value = dec % 2;

binary = value + binary;

dec /= 2;

}

return binary;

}

//returns a string representation of the number in octal

public String toOctalString( int dec )

{

String octal = " ";

while ( dec >= 1 )

{

int value = dec % 8;

octal = value + octal;

dec /= 8;

}

return octal;

}

public String toHexString( int dec )

{

String hexadecimal = " ";

while ( dec >= 1 )

{

int value = dec % 16;

switch (value)

{

case 10:

hexadecimal = "A" + hexadecimal;

break;

case 11:

hexadecimal = "B" + hexadecimal;

break;

case 12:

hexadecimal = "C" + hexadecimal;

break;

case 13:

hexadecimal = "D" + hexadecimal;

break;

case 14:

hexadecimal = "E" + hexadecimal;

break;

case 15:

hexadecimal = "F" + hexadecimal;

break;

default:

hexadecimal = value + hexadecimal;

break;

}

dec /= 16;

}

return hexadecimal;

}

public static void main( String args[])

{

NumberSystem apps = new NumberSystem();

apps.displayConversion();

}

}

User Avatar

Darien Renner

Lvl 10
4y ago

What else can I help you with?

Continue Learning about Other Math
Related Questions

Write a Program to convert decimal number into hexadecimal no without using function and string?

This is not a question.


Write a C program to convert hexadecimal number into decimal number?

pongada punda vayanungala ..................


What is one tool for reverse engineering software and five features of that tool?

hexadecimal dumper, which prints or displays the binary numbers of a program in hexadecimal format.


Write a program that prints a table of the binary octal and hexadecimal equivalents of the decimal numbers in the range 1 through to 256?

import java.util.Scanner; public class NumberSystem { public void displayConversion() { Scanner input = new Scanner(System.in); System.out.printf("%-20s%-20s%-20s%-20s\n", "Decimal", "Binary", "Octal", "Hexadecimal"); for ( int i = 1; i &lt;= 256; i++ ) { String binary = Integer.toBinaryString(i); String octal = Integer.toOctalString(i); String hexadecimal = Integer.toHexString(i); System.out.format("%-20d%-20s%-20s%-20s\n", i, binary, octal, hexadecimal); } } // returns a string representation of the decimal number in binary public String toBinaryString( int dec ) { String binary = " "; while (dec &gt;= 1 ) { int value = dec % 2; binary = value + binary; dec /= 2; } return binary; } //returns a string representation of the number in octal public String toOctalString( int dec ) { String octal = " "; while ( dec &gt;= 1 ) { int value = dec % 8; octal = value + octal; dec /= 8; } return octal; } public String toHexString( int dec ) { String hexadecimal = " "; while ( dec &gt;= 1 ) { int value = dec % 16; switch (value) { case 10: hexadecimal = "A" + hexadecimal; break; case 11: hexadecimal = "B" + hexadecimal; break; case 12: hexadecimal = "C" + hexadecimal; break; case 13: hexadecimal = "D" + hexadecimal; break; case 14: hexadecimal = "E" + hexadecimal; break; case 15: hexadecimal = "F" + hexadecimal; break; default: hexadecimal = value + hexadecimal; break; } dec /= 16; } return hexadecimal; } public static void main( String args[]) { NumberSystem apps = new NumberSystem(); apps.displayConversion(); } }


What is the 8086 program to find the sum of two digit n numbers?

To find the sum of two-digit numbers in an 8086 assembly program, you would typically load the two numbers into registers, add them using the ADD instruction, and store or display the result. Here's a simplified outline of the program: MOV AX, 12h ; Load first two-digit number (18 in decimal) MOV BX, 34h ; Load second two-digit number (52 in decimal) ADD AX, BX ; Add the two numbers ; AX now contains the sum (70 in decimal) This program assumes that the numbers are already defined and uses hexadecimal notation for clarity. The result can be further processed or displayed as needed.


What is hexadecimal code?

Computer engineers use to use the hexadecimal code to program computers, or the base 16. Hexadecimal numbers use the digits 0 through 9, plus the letters A through F to represent the digits 10 through 15.


Write a program to convert a 2 digit BCD number into hexadecimal number?

Write a program to convert a 2-digit BCD number into hexadecimal


2 Write a program to convert a 2-digit BCD number into hexadecimal?

WRITE A PROGRAM TO CONVERT A 2-DIGIT bcd NUMBER INTO HEXADECIMAL


1 To develop a program using the ADI instruction to add the two hexadecimal numbers 3AH and 48H and store the result in memory location 2100H?

Oh, what a happy little question! To add the two hexadecimal numbers 3AH and 48H using the ADI instruction, you can first load 3AH into the accumulator, then use the ADI 48H instruction to add 48H to the accumulator. Finally, you can store the result in memory location 2100H. Just remember to take your time, enjoy the process, and trust in your abilities to create something wonderful!


Write a program to sort 20 decimal numbers in decreasing order and print the result?

decimal[] a = new decimal[20]; // initialize to some numbers for (int i = 0; i &lt; 20; i++) { a[i] = i; } Array.Sort(a); //sorted in increasing order Array.Reverse(a); // decreasing foreach (decimal d in a) { Console.WriteLine(d); }


Algorithm of conversion decimal to hexadecimal?

The hexadecimal notation is base-16, so for small numbers, arrange them right to left as powers of 16 (units 0 to 9 and A through F representing 10, 11, 12, 13, 14, and 15).Examples: 21 = 15 hex (16+5) and 31 = 1F (16+15)For larger numbers, see the process at the related link below.Here is a program:#include#includevoid main(){int n;clrscr();printf("Enter Decimal Number: ");scanf("%d",&n);printf("Hexadecimal value is: %x",n);getch();}


How does a computer programmer use fractions?

A computer programmer can use fractions in his/her program simply by turning the fraction into a decimal. In a language like java, there is not extensive support nor a primitive data type for fractions, but you can store fractions as their decimal equivalents in things such as floats and doubles.