Represent integer as binary in C To practice my C, I've written a small function in C to display an integer as an 8-bit binary number. Please let me know how to improve this function, and other C-style coding conventions. Thanks!
/**
 * Converts an integer to binary.
 * 
 * @param num Integer to convert.
 * 
 * @return c-string.
**/
const char* to_binary(int num) {

    static char binary[10];
    binary[0] = '0';
    binary[1] = 'b';

    int value = 128;
    int number = num;

    for (int i = 2; i &lt; 10; i++) {
        if (number - value &gt;= 0) {
            binary[i] = '1';
            number = number - value;
        } else {
            binary[i] = '0';
        }
        value = value / 2;
    }

    return binary;

}

And here's how you call it:
int main() {

    const char* result = to_binary(146);

    printf(&quot;%s\n&quot;, result);

}
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
}