Advertisement
Natirium

String (Ascii/binary)

Jan 29th, 2018
138
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.70 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5.     char funktion1(char ascii_char){
  6.         char modulo;
  7.         unsigned int ascii_int = ascii_char;
  8.         char binary[9];
  9.  
  10.             for(int i=7; i > -1; i--){
  11.                 modulo = (char)ascii_int % 2+48;        //+ "\O"
  12.                 ascii_int = ascii_int/2;
  13.                 binary[i]= modulo;
  14.             }
  15.         printf("%s\n",binary);
  16.     }
  17.  
  18. int main(){
  19.     char eingabe[50];
  20.     int laenge;
  21.  
  22.     printf("Zeichen eingeben: \n");
  23.     fgets(eingabe,50,stdin);
  24.  
  25.     laenge = strlen(eingabe);
  26.     laenge--;                       // avoiding \0
  27.  
  28.         for(int i=0;i <laenge;i++){
  29.             printf("Zeichen:%c\t",eingabe[i]);
  30.             printf("Ascii:%d\t",eingabe[i]);
  31.             funktion1(eingabe[i]);
  32.         }
  33.  
  34.     return 0;
  35. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement