Advertisement
xBloodY

hexen

Sep 24th, 2022
1,004
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 0.86 KB | None | 0 0
  1. #include <stdio.h>
  2. #include "string.h"
  3. #include "malloc.h"
  4.  
  5. int main() {
  6.     char x[1000000];
  7.     scanf("%s", &x);
  8.     int len = strlen(x), sz = len * 4 + 1;
  9.     char* ans = (char*) malloc(sz);
  10.     memset(ans, '0', sz);
  11.     ans[sz - 1] = 0;
  12.     for (int i = 0; i < len; i++) {
  13.         int tmp = 0;
  14.         if (x[i] >= '0' && x[i] <= '9')
  15.             tmp = x[i]-'0';
  16.         else
  17.             tmp = 10 + (x[i] - 'A');
  18.         int k = 3;
  19.  
  20.         while (tmp > 0) {
  21.             int t = tmp & 1;
  22.             ans[i * 4 + k] = '0' + t;
  23.             tmp >>= 1;
  24.             k--;
  25.         }
  26.     }
  27.     int len2 = len*4, chek = 0, diff = 0;
  28.     for (int i = 0; i < len2; i++) {
  29.         if (ans[i] != '0') {
  30.             chek = 1;
  31.             diff = i;
  32.             break;
  33.         }
  34.     }
  35.     printf("%s", chek ? ans + diff : "0");
  36.     free(ans);
  37.     return 0;
  38. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement