Advertisement
Guest User

Untitled

a guest
Nov 19th, 2017
48
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 1.01 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4.  
  5. int main(){
  6.  
  7.     int input = 0;
  8.     int buffer = 0;
  9.     int i = 0;
  10.     int four = 0;
  11.     int value = -1;
  12.  
  13.     //while(1){
  14.  
  15.         printf("Ganzzahl eingeben: ");
  16.         value = scanf("%d", &input);
  17.  
  18.         while(value == 0){
  19.             printf("   Bitte Zahl eingeben!\n");
  20.             printf("Ganzzahl eingeben: ");
  21.             value = scanf("%d", &input);
  22.         }
  23.  
  24.  
  25.  
  26.  
  27.  
  28.             // input = -1;
  29.  
  30.         printf("%d in Hexadezimaldarstellung:\n    %X\n", input, input);
  31.         printf("%d in Binärdarstellung:\n    ", input);
  32.  
  33.         for(i = 31; i >= 0; i--){
  34.  
  35.             buffer = input >> i;
  36.  
  37.             if(buffer & 1){
  38.                 printf("1");
  39.                 four++;
  40.             }
  41.             else{
  42.                 printf("0");
  43.                 four++;
  44.             }
  45.  
  46.             if(four % 4 == 0){
  47.                 printf(" ");
  48.             }
  49.         }
  50.  
  51.         printf("\n");
  52.     //}
  53.  
  54.  
  55.     return 0;
  56. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement