মান लीজিয়ে আমাদের একটি অক্টাল সংখ্যা আছে। অক্টাল থেকে বাইনারি, হেক্সাডেসিমাল ইত্যাদি অন্যান্য বেসে রূপান্তর করার জন্য জাভা কোড নিচে দেওয়া হলো:
উদাহরণ
public class Demo{ public static String base_convert(String num, int source, int destination){ return Integer.toString(Integer.parseInt(num, source), destination); } public static void main(String[] args){ String my_num = "345"; int source = 8; int destination = 2; System.out.println("Converting the number from octal to binary: "+ base_convert (my_num, source, destination)); destination = 10; System.out.println("Converting the number from octal to decimal : "+ base_convert (my_num, source, destination)); destination = 16; System.out.println("Converting the number from octal to hexadecimal: "+ base_convert (my_num, source, destination)); } }আউটপুট
Converting the number from octal to binary: 11100101 Converting the number from octal to decimal : 229 Converting the number from octal to hexadecimal: e5
Demo ক্লাসে 'base_convert' নামে একটি ফাংশন সংজ্ঞায়িত করা হয়েছে। এই ফাংশন সোর্স বেস থেকে ডেস্টিনেশন বেসে ইন্টিজার পার্স করে, স্ট্রিং-এ রূপান্তর করে এবং আউটপুট হিসেবে রিটার্ন করে। main ফাংশনে সংখ্যা, সোর্স বেস এবং বিভিন্ন ডেস্টিনেশন বেসের মান সংজ্ঞায়িত করা হয়েছে। 'base_convert' ফাংশনটি সংখ্যা, সোর্স এবং ডেস্টিনেশন প্যারামিটার হিসেবে কল করা হয়েছে। প্রাসঙ্গিক আউটপুট প্রদর্শন করা হয়েছে।