Jump to content
Fórum Script Brasil
  • 0

Converter de Binário para decimal


Reaper

Question

Pessoal preciso converter de binário pra decimal.

Já fiz isso:

public static char ConverterParaCaracter ( int digito ){
    
        switch( digito ){
            case 0: return '0'; 
            case 1: return '1'; 
            case 2: return '2'; 
            case 3: return '3'; 
            case 4: return '4'; 
            case 5: return '5'; 
            case 6: return '6'; 
            case 7: return '7'; 
            case 8: return '8'; 
            case 9: return '9'; 
            case 10: return 'A'; 
            case 11: return 'B'; 
            case 12: return 'C'; 
            case 13: return 'D';
            case 14: return 'E'; 
            default : return 'F';
        }
    }
public static void ConverterDeDecimalParaBase ( int base, int numero, String numStr ){
        int resto = 0,
            expoente = 0;
        
        while (numero > 0){
        
          resto = numero%base;
          int valor = ConverterParaCaracter( resto );
          numStr = valor * Math.pow(10, expoente);
          expoente = expoente + 1;
          numero = numero/base;
        }
    }

Porém não sei terminar. Por favor me ajudem.

Edited by Reaper
Link to comment
Share on other sites

0 answers to this question

Recommended Posts

There have been no answers to this question yet

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Answer this question...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.



  • Forum Statistics

    • Total Topics
      152.2k
    • Total Posts
      652k
×
×
  • Create New...