Converting an int to a binary in Java

 

By using Integer.toBinaryString() we can convert integer string into binary value.This is the best way to convert integer to a binary string in Java.

 

 

Integer.toBinaryString() returns a string(group of character) representation of the integer argument as an unsigned integer in base 2(0,1)( binary form).

Example...

import javax.swing.*;

class StringConversions

{

public static void main(String args[])

{

int no = 196488;

JOptionPane.showMessageDialog(null,"in binary: : :" +no   + Integer.toBinaryString(no));

System.out.println(no);

System.out.println(Integer.toBinaryString(no));

}

}

Output...

 Convert int to binary

About Us

Rekha SetiaRekha Setia is a passionate blogger of Extra Computer Notes. if you have any ideas or any request me @