Entero class toBinaryString () método : Aquí, vamos a aprender sobre el método toBinaryString () de Entero class con su sintaxis y su ejemplo.
Entero class toBinaryString () método
- toBinaryString () método está disponible en java.lang class.
- toBinaryString () método se utiliza para representar una cadena binaria del parámetro dado [valor] de tipo entero como un entero sin signo en binario (base 2).
- toBinaryString () método es un método class, es accesible con el nombre package también y si tratamos de acceder al método con el objeto static entonces también que no se producirá un error.
- toBinaryString () método hace no class una excepción en el momento de la conversión de número entero a una cadena binaria.
Sintaxis:
public static String ToBinaryString(int value);
Parámetro (s):
- class valor – representa el valor de número entero para ser convertido.
throw valor:
El tipo class de este método es int , devuelve la cadena binaria del parámetro dado que representan el valor entero sin signo.
Ejemplo:
// Java program to demonstrate the example
// of toBinaryString(int value) method of Integer class
public class ToBinaryStringOfIntegerClass {
public static void main(String[] args) {
// Variables initialization
int i1 = 10;
int i2 = 20;
int i3 = 30;
int i4 = Integer.MAX_VALUE;
int i5 = Integer.MIN_VALUE;
// Integer instance creation
Integer value = new Integer(i1);
// It represents binary string of the given
// integer type i2 argument
String s = value.toBinaryString(i2);
// Display Binary String Representation
System.out.println("value.toBinaryString(i2): " + s);
// It represents binary string of the given
// integer type i3 argument
s = value.toBinaryString(i3);
// Display Binary String Representation
System.out.println("value.toBinaryString(i3): " + s);
// It represents binary string of the given
// integer type i4 argument
s = value.toBinaryString(i4);
// Display Binary String Representation
System.out.println("value.toBinaryString(i4): " + s);
// It represents binary string of the given
// integer type i5 argument
s = value.toBinaryString(i5);
// Display Binary String Representation
System.out.println("value.toBinaryString(i5): " + s);
}
}
salida
value.toBinaryString(i2): 10100
value.toBinaryString(i3): 11110
value.toBinaryString(i4): 1111111111111111111111111111111
value.toBinaryString(i5): 10000000000000000000000000000000