May 2021 3 160 Report
¿convertir un texto a codigo binario en C?

hola amigos les dejo un programita que hice....se trata de introducir un texto y que el programa lo convierta a codigo binario incluyendo los espacios..

#include<stdio.h>

#include <string.h>

main()

{

char texto[300];

int contador=0, num,resul,cerosunos[20],i;

clrscr();

printf("introduzca un texto para convertirlo a codigo binario:\n");

gets(texto);

while(contador < strlen(texto))

{

i=1;

num = texto[contador];

while(num>0)

{

resul = num%2;

if(resul==0)

{

cerosunos[i]=0;

i=i+1;

}

else

{

cerosunos[i]=1;

i=i+1;

num=num-1;

}

num=num/2;

}

i=i-1;

while(i>0)

{

printf("%i",cerosunos[i]);

i=i-1;

}

printf(" ");

contador = contador+1;

}

getch();

}


Please enter comments
Please enter your name.
Please enter the correct email address.
You must agree before submitting.

Answers & Comments




Helpful Social

Copyright © 2024 Q2A.MX - All rights reserved.