immuntasir

446

Feb 16th, 2015
303
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.91 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <math.h>
  5. int bin1[50], bin2[50];
  6. int main() {
  7.     int T,hex1,hex2,bin,result,i,j,k;
  8.  
  9.     char sign;
  10.     scanf("%d",&T);
  11.     while (T--) {
  12.         scanf("%X %c %X",&hex1, &sign, &hex2);
  13.  
  14.         if (sign == '+') result = hex1 + hex2;
  15.         else if (sign == '-')  result = hex1 - hex2;
  16.  
  17.         i=0;
  18.         while (hex1) {
  19.             bin1[i] = hex1%2;
  20.             hex1 = hex1/2;
  21.             i++;
  22.         }
  23.  
  24.         for (j=12;j>=0;j--) {
  25.             printf("%d",bin1[j]);
  26.             bin1[i] = 0;
  27.         }
  28.  
  29.         printf(" %c ",sign);
  30.         i =0;
  31.  
  32.         while (hex2) {
  33.             bin2[i] = hex2%2;
  34.             hex2 = hex2/2;
  35.             i++;
  36.         }
  37.  
  38.         for (j=12;j>=0;j--) {
  39.             printf("%d",bin2[j]);
  40.             bin2[j] = 0;
  41.         }
  42.  
  43.         printf(" = %d\n",result);
  44.     }
  45.     return 0;
  46. }
Advertisement
Add Comment
Please, Sign In to add comment