Advertisement
Mastercpp

Convertir decimal a binario

Oct 28th, 2015
131
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 0.43 KB | None | 0 0
  1. import java.util.Scanner;
  2.  
  3. public class Binarios{
  4.     public static void main(String[] args) {
  5.        
  6.         Scanner leer = new Scanner(System.in);
  7.  
  8.         System.out.print("ingrese un numero: ");
  9.         long decimal=leer.nextLong();
  10.         long aux = decimal;
  11.  
  12.         String binario = "";
  13.  
  14.         while(aux > 0){
  15.             binario = aux%2+binario;
  16.             aux /= 2;
  17.         }
  18.  
  19.         System.out.println("El numero decimal "+decimal+" en binario es "+binario);
  20.        
  21.     }
  22.  
  23.  
  24. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement