TADS IFGoiano-Urutaí
Gostaria de reagir a esta mensagem? Crie uma conta em poucos cliques ou inicie sessão para continuar.
Procurar
 
 

Resultados por:
 


Rechercher Pesquisa avançada

Últimos assuntos
» Dowloand de Videos youtube Sem Permissão adminstrador
Converte Caractere em binario  EmptySeg Jan 02, 2023 2:13 pm por juk

» Cypecad 2019
Converte Caractere em binario  EmptySeg Jan 02, 2023 1:41 pm por juk

» Atualizando é instalando o IExplorer 11 no windows 7
Converte Caractere em binario  EmptyTer Ago 30, 2022 10:54 pm por juk

» COMO HABILITAR INTERNET EXPLORER NO WINDOWS 10
Converte Caractere em binario  EmptySex Abr 29, 2022 6:43 pm por juk

» Usando o Monitor de Recursos do sistema para identificar processos Associados.
Converte Caractere em binario  EmptyQua Abr 06, 2022 10:19 am por juk

» Fazendo backup do anydesk
Converte Caractere em binario  EmptyTer Abr 05, 2022 7:30 pm por juk

» Recuperando Favoritos, senhas apos formatar o navegador (Mozilla Firefox ou Chrome)
Converte Caractere em binario  EmptyTer Abr 05, 2022 7:28 pm por juk

» Comando para tentar recuperar o windows
Converte Caractere em binario  EmptyQua Out 27, 2021 5:52 pm por juk

» NGROK para divulgação de site remoto
Converte Caractere em binario  EmptyTer Set 29, 2020 9:40 am por juk

Quem está conectado?
2 usuários online :: 0 registrados, 0 invisíveis e 2 visitantes

Nenhum

[ Ver toda a lista ]


O recorde de usuários online foi de 192 em Ter Out 26, 2021 6:07 am

Converte Caractere em binario

Ir para baixo

Converte Caractere em binario  Empty Converte Caractere em binario

Mensagem  juk Dom Nov 24, 2013 7:45 pm

Converte Caractere em binario  Char_to_int_to_bin

Código:

#include<stdio.h>

#include<conio.h>
 
void inttobin(int); //the function that will convert the integer value to binary
 
main(){
       int n, count;
       //array of small letters
       char sletter[27] = "abcdefghijklmnopqrstuvwxyz";
       //array of big letters
       char bletter[27] = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";
      
      //check the int value of small letters from a to z
       for(count = 0; count<26; count++){            
           n=sletter[count]; //get int value of a characters
            printf("%c = %d = ",sletter[count],n ); //print a character and its integer value
            inttobin(n);//calls function to convert integer value to binary and prints it
            printf("\n");
       }
      
      printf("\nThe Big Letters\n\n");
      
      //check the int value of BIG letters from A to Z
       for(count = 0; count<26; count++){            
           n=bletter[count];//get int value of a characters
            printf("%c = %d = ",bletter[count],n );//print a character and its integer value
            inttobin(n);//calls function to convert integer value to binary and prints it
            printf("\n");
       }
            
       getch(); //i don't know, it's my practice so the program won't terminate immediately after running.
       return 0;
       }
 
//code for int to bin      
void inttobin(int n){
     /*
       >This function convert the integer parameter to binary and displays the results
       >The binary is stored on the array bin[] defined inside this function
       >This function only converts integer value form 1 to 127
     */
    
      char bin[7]; //the array of char that will represent the binary value
       int count;
       //check if the integer value is divisible by 64  
       if((n/64)==1){
            bin[0]='1'; //if TRUE, set the 64 value in binary array by seting it 1
            n=n%64;     //set n to n mod 64 for futher computation          
       }
       else{bin[0]='0';}//if FALSE, set it as 0
      
      //check if the integer value is divisible by 32  
      if((n/32)==1){
             bin[1]='1'; //if TRUE, set the 32 value in binary array by setting it 1
             n=n%32;     //set n to n mod 32 for futher computation                  
      }
       else{bin[1]='0';}//if FALSE, set is as 0
        
      //the same process will continue until...
      if((n/16)==1){ //***16***
            bin[2]='1';
            n=n%16;              
       }
       else{bin[2]='0';}
      
     //until....  
      if((n/8)==1){  //***8***
            bin[3]='1';
            n=n%8;              
       }
       else{bin[3]='0';}
      
      //wait for it...
       if((n/4)==1){  //***4***
            bin[4]='1';
            n=n%4;              
       }
       else{bin[4]='0';}
       //almost there...  
       if((n/2)==1){  //***2***
            bin[5]='1';
            n=n%2;              
       }
       else{bin[5]='0';}
       //Tadah!!! it reaches the last binary digit which represent the integer 1
      if((n/1)==1){//***1***
            bin[6]='1';
            n=n%1;              
       }
       else{bin[6]='0';}
      
      //after the binary array is set, the function will output the produced string of binary digit  
       for(count=0;count<7;count++){
           printf("%c ",bin[count]);
       }
 
}
juk
juk

Mensagens : 262
Data de inscrição : 02/04/2012

Ir para o topo Ir para baixo

Ir para o topo

- Tópicos semelhantes

 
Permissões neste sub-fórum
Não podes responder a tópicos