SHARE
TWEET

Untitled

a guest Dec 6th, 2019 104 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. void reduce_binary(void *s, void *d){
  2.     int *ret = d;
  3.     char *str = s;
  4.     if (strlen(str) == 32 && *str-48 == 1){
  5.         *ret -= INT_MAX;
  6.         *ret -= 1;
  7.     } else {
  8.         *ret += (*str - 48) * (1 << (strlen(str) - 1));
  9.     }
  10. }
  11.  
  12. void binStrHelp(void *s, void *d){
  13.     char **strs = s;
  14.     int *ret = d;
  15.  
  16.     reduce(*strs, strlen(*strs), sizeof(char), ret,  reduce_binary);
  17. }
  18.  
  19. void set_zero(void *s, void *d){
  20.     int *src = s;
  21.     *src = 0;
  22. }
  23.  
  24. int *binStrArrToIntArr(char **strs, size_t n) {
  25.     int *ret = malloc(sizeof(int) * n);
  26.     map(ret, n, sizeof(int), ret, sizeof(int), set_zero);
  27.     map(strs, n, sizeof(char*), ret, sizeof(int), binStrHelp);    
  28.  
  29.     return ret;
  30.  
  31. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Not a member of Pastebin yet?
Sign Up, it unlocks many cool features!
 
Top