SHARE
TWEET

Untitled

a guest Dec 13th, 2018 55 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. #include <stdio.h>
  2. #include <inttypes.h>
  3.  
  4. int countBits(uint32_t x) {
  5.     int i, left, right, counter;
  6.     _Bool first = 0;
  7.     for (i = 31; i >= 0; i--) {
  8.         if ((x & ((uint32_t)1 << i)) != 0) {
  9.             if (!(first)) {
  10.                 first = 1;
  11.                 left = i;
  12.             }
  13.             if (first)
  14.                 right = i;
  15.         }
  16.     }
  17.     if (first) {
  18.         counter = left - right + 2;
  19.         //printf("\n%d\n", counter);
  20.         return counter;
  21.     }
  22.     //printf("\n0\n");
  23.     return 0;
  24. }
  25.  
  26. _Bool floatPres(uint32_t n) {
  27.     if (countBits(n) <= 21)
  28.         return 1;
  29.     return 0;
  30. }
  31.  
  32. int main() {
  33.     uint32_t num;
  34.     while (scanf("%" SCNu32, &(num)) != EOF) {
  35.         //printf("%" PRIu32 "\n", num);
  36.         //countBits(num);
  37.         if (floatPres(num))
  38.             printf("1\n");
  39.         else
  40.             printf("0\n");
  41.     }
  42.     return 0;
  43. }
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