Java Decoder

  • November 2019
  • PDF

This document was uploaded by user and they confirmed that they have the permission to share it. If you are author or own the copyright of this book, please report to us by using this DMCA report form. Report DMCA


Overview

Download & View Java Decoder as PDF for free.

More details

  • Words: 258
  • Pages: 2
// traer paquetes de java import java.io.*; import javax.swing.*; public class decbin { //el metodo main inicia public static void main ( String arg[] ) throws IOException { String NumADividir; String Resultado = ""; int bin[] = new int[100]; int size = 100, posStart = -1; int x = 0, temp; NumADividir = JOptionPane.showInputDialog ( "Número entero a convertir ? " ) ; // verifica que la cadena no sea mayor a 8 caracteres if ( NumADividir.length () <= 8 ) { // inicializa vector for ( x = 0; x < size; x++ ) bin[x] = -1; temp = Integer.parseInt ( NumADividir ) ; bin[0] = temp % 2; // toma los binarios for ( x = 1; x < size; x++ ) { temp /= 2; bin[x] = temp % 2; } // recorta para no tomar los ceros excedentes for ( x = size - 1; x >= 0; x-- ) if ( bin[x] == 1 ) { posStart = x; break; } // forma la cadena final for ( x = posStart; x >= 0; x-- ) Resultado = Resultado + Integer.toString ( bin[x] ); JOptionPane.showMessageDialog ( null, "Binario: " + Resultado, "Resultados", JOptionPane.PLAIN_MESSAGE ); } else { JOptionPane.showMessageDialog ( null, "La cantidad contiene más de 8 digitos", "Error !!!!", JOptionPane.PLAIN_MESSAGE ); } System.exit ( 0 ); //terminar aplicacion de la ventana } //fin del metodo main } // fin de la clase

int val = Integer.parseInt("101",2); //esto va dentro de una clase, String val = Integer.toString(5,2); //dentro de tu clase, en el lugar

Related Documents

Java Decoder
November 2019 14
Decoder
November 2019 26
Decoder
May 2020 18
Decoder
November 2019 24
Decoder
November 2019 14
Manuale Decoder
October 2019 23