Procurar
Últimos assuntos
Quem está conectado?
Há 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
Página 1 de 1
Converte Caractere em binario
- 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- Mensagens : 262
Data de inscrição : 02/04/2012
Página 1 de 1
Permissões neste sub-fórum
Não podes responder a tópicos
Seg Jan 02, 2023 2:13 pm por juk
» Cypecad 2019
Seg Jan 02, 2023 1:41 pm por juk
» Atualizando é instalando o IExplorer 11 no windows 7
Ter Ago 30, 2022 10:54 pm por juk
» COMO HABILITAR INTERNET EXPLORER NO WINDOWS 10
Sex Abr 29, 2022 6:43 pm por juk
» Usando o Monitor de Recursos do sistema para identificar processos Associados.
Qua Abr 06, 2022 10:19 am por juk
» Fazendo backup do anydesk
Ter Abr 05, 2022 7:30 pm por juk
» Recuperando Favoritos, senhas apos formatar o navegador (Mozilla Firefox ou Chrome)
Ter Abr 05, 2022 7:28 pm por juk
» Comando para tentar recuperar o windows
Qua Out 27, 2021 5:52 pm por juk
» NGROK para divulgação de site remoto
Ter Set 29, 2020 9:40 am por juk