Ir al contenido principal

Hi, I'm Mariano Guerra, below is my blog, if you want to learn more about me and what I do check a summary here: marianoguerra.github.io or find me on twitter @warianoguerra or Mastodon @marianoguerra@hachyderm.io

sobre el post anterior

el post anterior dice lo siguiente:

Titulo: elite
Contenido: Este texto es exclusivo para personas
que hablan binario si no lees binario estas out.

no crean que me puse a escribir en binario, hice un programa en C.

codigo:


#include <stdio.h>

int base2[] = { 128 , 64 , 32 , 16 , 8 , 4 , 2 , 1 };

char * charToBin( char c )
{
int i;
char * str = ( char * ) malloc( sizeof( char ) * 9 );

for( i = 0 ; i str[ i ] = ( ( c & base2[ i ] ) != 0 )?'1':'0';

str[ 8 ] = '\0';

return str;
}

int main( int argc , char ** argv )
{
FILE * pf;
char * str;

if( argc != 2 )
{
fprintf( stderr , "\nUSO: ./bin texto.txt\n" );
return 1;
}

pf = fopen( argv[ 1 ] , "r" );

if( !pf )
{
fprintf( stderr , "\nNo se pudo abrir el archivo\n" );
return 1;
}

while( !feof( pf ) )
{
str = charToBin( fgetc( pf ) );
printf( "%s" , str );
free( str );
}

printf( "\n" );

fclose( pf );
return 0;
}

para compilar: gcc bin.c -o bin
para ejecutar: ./bin texto.txt