fork download
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <math.h>
  4.  
  5. size_t bits_needed(int n)
  6. {
  7. return floor(log2(n) + 1);
  8. }
  9.  
  10. char *to_binary_string(int n)
  11. {
  12. size_t num_elements = bits_needed(n) + 1;
  13. char *bit_chars = malloc(num_elements);
  14.  
  15. bit_chars[num_elements - 1] = '\0';
  16.  
  17. while (--num_elements) {
  18. int quotient = n / 2, remainder = n % 2;
  19. printf("%d / 2 = %d, %d %% 2 = %d\n", n, quotient, n, remainder);
  20. bit_chars[num_elements - 1] = remainder == 1 ? '1' : '0';
  21. n = quotient;
  22. }
  23.  
  24. return bit_chars;
  25. }
  26.  
  27. int main()
  28. {
  29.  
  30. int a = 99, b = 131;
  31.  
  32. //puts(to_binary_string(a));
  33. //puts(to_binary_string(b));
  34.  
  35. printf("%d %.0f", 16 >> 4);
  36.  
  37. return 0;
  38. }
  39.  
Success #stdin #stdout 0s 2168KB
stdin
Standard input is empty
stdout
1 -695059343663969356836897207796590081181616953715610143231993599957863304199046913793001927391978233303776914777953892025967192921484401420299117266414338886244618764482582109623441745662396792797003411644274840041074144696282671325251410889012812256745083284765016064