Java Conversion of Octal Value to Binary, Decimal & HexaDecimal

  1. Octal to Binary conversion in Java
  2. Octal to Decimal conversion in Java
  3. Octal to HexaDecimal conversion in Java

Note
Here I am using,
OS : Linux (Ubuntu 12.04)
IDE : Eclipse Tool
Eclipse : Juno (Version 4.2.0)
Package : Default package

A. Octal to Binary conversion in Java


Octal_Binary.java

import java.util.Scanner;
 
public class Octal_Binary {
	
	Scanner scan;
	int num;
	
	void getVal() {
		
		System.out.println("Octal to Binary");
		scan = new Scanner(System.in);
		
		System.out.println("\nEnter the number :");
		num = Integer.parseInt(scan.nextLine(), 8);
	}
	
	void convert() {
		
		String binary = Integer.toBinaryString(num);
		
		System.out.println("Binary Value is : " + binary);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Octal_Binary obj = new Octal_Binary();
		
		obj.getVal();
		obj.convert();
	}
}

Sample Output

Octal to Binary

Enter the number :
10
Binary Value is : 1000




B. Octal to Decimal conversion in Java


Octal_Decimal.java

import java.util.Scanner;
 
public class Octal_Decimal {
	
	Scanner scan;
	int num;
	
	void getVal() {
		
		System.out.println("Octal to Decimal");
		scan = new Scanner(System.in);
		
		System.out.println("\nEnter the number :");
		num = Integer.parseInt(scan.nextLine(), 8);
	}
	
	void convert() {
		
		String decimal = Integer.toString(num);
		
		System.out.println("Decimal Value is : " + decimal);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Octal_Decimal obj = new Octal_Decimal();
		
		obj.getVal();
		obj.convert();
	}
}

Sample Output

Octal to Decimal

Enter the number :
10
Decimal Value is : 8




C. Octal to HexaDecimal conversion in Java


Octal_Hexa.java

import java.util.Scanner;
 
public class Octal_Hexa {
	
	Scanner scan;
	int num;
	
	void getVal() {
		
		System.out.println("Octal to HexaDecimal");
		scan = new Scanner(System.in);
		
		System.out.println("\nEnter the number :");
		num = Integer.parseInt(scan.nextLine(), 8);
	}
	
	void convert() {
		
		String hexa = Integer.toHexString(num);
		
		System.out.println("HexaDecimal Value is : " + hexa);
	}
}
 
class MainClass {
	
	public static void main(String args[]) {
		
		Octal_Hexa obj = new Octal_Hexa();
		
		obj.getVal();
		obj.convert();
	}
}

Sample Output

Octal to HexaDecimal

Enter the number :
15
HexaDecimal Value is : d






SHARE THIS PAGE



product 2

product 3

Feedbacks : balaji.scz@gmail.com