Ver Mensaje Individual
  #4 (permalink)  
Antiguo 15/10/2014, 01:15
Avatar de Profesor_Falken
Profesor_Falken
 
Fecha de Ingreso: agosto-2014
Ubicación: Mountain View
Mensajes: 1.323
Antigüedad: 9 años, 8 meses
Puntos: 182
Respuesta: Multiplicar 2 variables char byte a byte[C]

Buenas,

El ejemplo que te da eferion es ya completo. Te da el binario en formato hexadecimal y solo tienes que convertir la representacion:

0000 <-> 0
0001 <-> 1
0010 <-> 2
0011 <-> 3
0100 <-> 4
0101 <-> 5
0110 <-> 6
0111 <-> 7
1000 <-> 8
1001 <-> 9
1010 <-> A
1011 <-> B
1100 <-> C
1101 <-> D
1110 <-> E
1111 <-> F

Si lo que quieres es ir por la via rapida:

Código C:
Ver original
  1. #include <stdio.h>
  2. #include <string.h>
  3.  
  4. void printStringAsBinary(const char *input)
  5. {
  6.     const char *temp = input;
  7.     int i = 7, j =0;;
  8.     int inputLen = strlen(input);
  9.  
  10.     for (j = 0; j < inputLen; j++) {
  11.         while (i>=0) {
  12.             if (*temp & (1 << i)) {
  13.                printf("1");
  14.             } else {
  15.                 printf("0");
  16.             }
  17.             i--;
  18.         }
  19.         temp = temp+1;
  20.         i = 7;
  21.         printf(" ");
  22.     }
  23. }
  24.  
  25. int main(void)
  26. {
  27.   const char* cadena = "Programacion";
  28.  
  29.   printStringAsBinary(cadena);
  30.  
  31.   return 0;
  32. }

Resultado: 01010000 01110010 01101111 01100111 01110010 01100001 01101101 01100001 01100011 01101001 01101111 01101110


Un saludo
__________________
If to err is human, then programmers are the most human of us