#include <unistd.h>
void int_to_binary_string(int num, char *bin_str) {
    int i = 7;
    while (num > 0) {
        bin_str[i--] = (num & 1) + '0';
        num >>= 1;
    }
    bin_str[8] = '\0';  // Null terminator
}

int main() {
    int num = 42;
    char bin_str[9];  // Pre-allocate a buffer for the binary string (8 characters + null terminator)
int_to_binary_string(num, bin_str);

    write(1, "Binary representation of ", 25);
    write(1, &num, sizeof(num));
    write(1, ": ", 2);
    write(1, bin_str, 8);
    write(1, "\n", 1);

    return 0;
}

Embed on website

To embed this project on your website, copy the following code and paste it into your website's HTML: