How to Get Binary Number of an Integer in Java


In this example, we will convert integer to binary number with toBinaryString method of Integer wrapper class.

Source Code

package com.beginner.examples;

public class GetBinary {

	public static void main(String[] args) {

		Integer integer = new Integer(60);

		// Use the toBinaryString() method in the Integer class to get the
		// binary number
		String strBinary = Integer.toBinaryString(integer);

		System.out.println(integer + ":" + strBinary);
	}

}

Output:

60:111100
Subscribe
Notify of
guest
0 Comments
Inline Feedbacks
View all comments