Represent integer as binary in C
More specific types are available for an eight bit number, such as uint8_t
static keyword is dangerous (when used as an output buffer) and results in weird behaviour if your method is called twice
The arithmetic can be replaced with a more simple &amp; (bitwise AND)

void to_binary(uint8_t x, char *output) {
    *output++ = '0';
    *output++ = 'b';
    for (int mask = 1&lt;&lt;CHAR_BIT-1; mask!=0 ; mask&gt;&gt;=1) {
        *output++ = x &amp; mask ? '1':'0'; 
    }
    *output = 0; // null terminate the string
}