fork download
  1. #include <stdio.h>
  2.  
  3. char buffer[9] = {};
  4.  
  5. char* atob(char ch, char *buffer) {
  6. // Check for lowercase alphabets (a-z) and valid buffer
  7. if (ch < 'a' || ch > 'z') {
  8. return NULL; // Indicate error
  9. }
  10.  
  11. // Convert ASCII value to binary
  12. int ascii_value = ch;
  13. int i;
  14.  
  15. // Build the binary string in the provided buffer (reverse order)
  16. for (i = 0; i < 8; i++) {
  17. buffer[i] = (ascii_value & (1 << (7 - i))) ? '1' : '0';
  18. }
  19.  
  20. // Add null terminator at the end (overwrite buffer[8] if provided)
  21. buffer[8] = '\0';
  22.  
  23. return buffer;
  24. }
  25.  
  26. int main(void) {
  27. printf("%c -> atob -> %s", 'd', atob('d',&buffer));
  28. return 0;
  29. }
  30.  
Success #stdin #stdout 0.01s 5296KB
stdin
Standard input is empty
stdout
d -> atob -> 01100100