Advertisement
FoxTuGa

Conversion Hex - <Old>

May 8th, 2011
128
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.95 KB | None | 0 0
  1. #include <stdio.h>
  2.  
  3. int dec, hex, resto, hf, rf;
  4. char A, B, C, D, E, F, r, h;
  5.  
  6.  
  7.  
  8. int main()
  9. {
  10.     printf("\nIntroduza um numero inteiro entre 0 e 255:  ");
  11.     scanf("%d", &dec);
  12.  
  13.     hex = dec / 16;
  14.     resto = dec % 16;
  15.  
  16.     if( dec < 0 || dec > 255 )
  17.     {
  18.         printf("\n\t ERRO: Introduza um Numero entre 0 e 255 \n\n\n");
  19.         return 0;
  20.     }
  21.  
  22.     printf("\n\n Hex = ");
  23.  
  24.     if( hex <= 9 )
  25.     {
  26.         printf("%d", hex);
  27.     }
  28.    
  29.     if( hex > 9 )
  30.     {
  31.     if( hex == 10 )
  32.         h = 'A';
  33.     if( hex == 11 )
  34.         h = 'B';
  35.     if( hex == 12 )
  36.         h = 'C';
  37.     if( hex == 13 )
  38.         h = 'D';
  39.     if( hex == 14 )
  40.         h = 'E';
  41.     if( hex == 15 )
  42.         h = 'F';
  43.     printf("%c", h);
  44.     }
  45.  
  46.     if( resto <= 9 )
  47.     {
  48.         printf("%d", resto);
  49.     }
  50.  
  51.     if( resto > 9 )
  52.     {
  53.     if( resto == 10 )
  54.         r = 'A';
  55.     if( resto == 11 )
  56.         r = 'B';
  57.     if( resto == 12 )
  58.         r = 'C';
  59.     if( resto == 13 )
  60.         r = 'D';
  61.     if( resto == 14 )
  62.         r = 'E';
  63.     if( resto == 15 )
  64.         r = 'F';
  65.  
  66.     printf("%c", r);
  67.     }
  68.  
  69.     printf("\n\n\n");
  70.  
  71.     return 0;
  72. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement