SHARE
TWEET

déambulateur

a guest Feb 27th, 2020 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. /*
  2. ** EPITECH PROJECT, 2020
  3. ** navy
  4. ** File description:
  5. ** convert
  6. */
  7.  
  8. #include "../../include/util.h"
  9.  
  10. int bin_to_int(char *bits)
  11. {
  12.     unsigned char *p = bits;
  13.     unsigned int r = 0;
  14.  
  15.     while (p && *p) {
  16.         r <<= 1;
  17.         r += (unsigned int)((*p++) & 0x01);
  18.     }
  19.     return (r);
  20. }
  21.  
  22. int my_getnbr(char const *str)
  23. {
  24.     int sign = 1;
  25.     int result = 0;
  26.  
  27.     while (*str == '-' || *str == '+') {
  28.         if (*str == '-')
  29.             sign = - sign;
  30.         str = str + 1;
  31.     }
  32.     while (*str != '\0' && *str >= '0' && *str <= '9') {
  33.         if ((result > 214748364) || (result == 214748364 && *str > 7 &&
  34.         sign == 1) || (result == 214748364 && *str > 8 && sign == -1)) {
  35.             return (0);
  36.         }
  37.         result = result * 10 + *str - 48;
  38.         str = str + 1;
  39.     }
  40.     if (sign == -1)
  41.         result = - result;
  42.     return (result);
  43. }
  44.  
  45. int is_number(char const *str)
  46. {
  47.     for (int i = 0; str[i]; ++i)
  48.         if (str[i] < '0' || str[i] > '9')
  49.             return (NULL);
  50.     return (my_getnbr(str));
  51. }
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
Top