Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <stdio.h>
- #include <stdlib.h>
- #include <string.h>
- #include <math.h>
- int bin1[50], bin2[50];
- int main() {
- int T,hex1,hex2,bin,result,i,j,k;
- char sign;
- scanf("%d",&T);
- while (T--) {
- scanf("%X %c %X",&hex1, &sign, &hex2);
- if (sign == '+') result = hex1 + hex2;
- else if (sign == '-') result = hex1 - hex2;
- i=0;
- while (hex1) {
- bin1[i] = hex1%2;
- hex1 = hex1/2;
- i++;
- }
- for (j=12;j>=0;j--) {
- printf("%d",bin1[j]);
- bin1[i] = 0;
- }
- printf(" %c ",sign);
- i =0;
- while (hex2) {
- bin2[i] = hex2%2;
- hex2 = hex2/2;
- i++;
- }
- for (j=12;j>=0;j--) {
- printf("%d",bin2[j]);
- bin2[j] = 0;
- }
- printf(" = %d\n",result);
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment