answersLogoWhite

0


Best Answer

public class Dataconversion {

public static void main(String[] args) {

System.out.println("Data types conversion example!");

int in = 44;

System.out.println("Integer: " + in);

//integer to binary

String by = Integer.toBinaryString(in);

System.out.println("Byte: " + by);

//integer to hexadecimal

String hex = Integer.toHexString(in);

System.out.println("Hexa decimal: " + hex);

//integer to octal

String oct = Integer.toOctalString(in);

System.out.println("Octal: " + oct);

}

}

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

13y ago

Here is a simple way to display a decimal integer as an octal number:

Integer i = 10;

System.out.println(Integer.toOctalString(i));

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: How do you write a Java program to convert a decimal number to an octal number?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Convert the hexadecimal number BB895C to octal and Decimal?

BB895C: Octal = 56704534 Decimal = 12290396


Convert the hexadecimal number A45C to octal and decimal?

A45C: Decimal = 42076 Octal = 122134


What is the c program to find the octal equivalent of an integer?

void Decimal_to_Octal(){int n,r[10],i;coutn;cout


Conversion of binary to octal?

Binary is a base 2 number system, while octal is base 8. This happens to make conversion between binary and octal fairly trivial, although more complex than conversion to hexadecimal. To convert to octal from binary, take each three bits, starting from the least significant bit, and convert them to their octal equivalent. Examples: 25510 = 111111112 = 11 111 111 = 3778 17410 = 101011102 = 10 101 110 = 2568 You can repeat this process for as many bits as you need. A 24-bit number should translate into 8 octal numbers, for reference.


How do you convert a decimal number to its octal What is the algorithm for it?

Repeatedly divide the number by 8 until the number is zero. Take the remainders from each division (the remainders will always be in the range 0 to 7 inclusive). The first division finds the lowest-order digit, the last finds the highest-order digit. Example: Decimal value: 421 421 / 8 = 52 r 5 52 / 8 = 6 r 4 6 / 8 = 0 r 6 The remainders are 6, 4 and 5, so 421 decimal is 645 octal. To convert from octal to decimal, multiply each octal digit by 8^n, where n is the zero-based order of the digit (0 being the lowest order), then sum the products. Example: Octal number: 645 5 * (8^0) = 5 * 1 = 5 4 * (8^1) = 4 * 8 = 32 6 * (8^2) = 6 * 64 = 384 384 + 32 + 5 = 421 Note that n^0 = 1 for all n>=0.