Advertisement
devunes

HMF

Jun 26th, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.69 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3.  
  4. char bin2char(char *num){
  5.     int i, j = 0, temp = 0; char output;
  6.     for (i = strlen(num)-1; i >= 0; i--) {
  7.         if (num[i] == '1')
  8.             temp += pow(2, j);
  9.         j++;
  10.     }
  11.     output = temp;
  12.     printf("%c", output);
  13.     return output;
  14. }
  15.  
  16. int main ()
  17. {
  18.     const char* a = "1001000 1010101";
  19.     char b[8];
  20.     int i = 0, j = 0;
  21.    
  22.     printf("%d\n", strlen(a));
  23.     for (i = 0; i < strlen(a); i++){
  24.              if (j == 7) {
  25.          bin2char(b);
  26.         }
  27.        
  28.         if (a[i] != ' ') {
  29.             b[j] = a[i];
  30.             j++;
  31.         }
  32.    
  33.        
  34.        
  35.        
  36.        
  37.        
  38.      
  39.     }
  40. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement