I want to convert a decimal number to a 16 bit binary number.
My code does not work at all but I am sure that I did the right steps.
Hope for some help.
#include <stdio.h>
#include <stdlib.h>
const int BIT = 16;
char binaer(int i) {
    char str[BIT];
    int j = 0;
    if(0 <= i && i <= 65535) {
        for(int j = 0; j < BIT + 1; j++) {
            if (i % 2 == 0) {
                str[j] = '0';
            } else {
                str[j] = '1';
            }
            i = i / 2;
        }
    }
    for(int x = BIT - 1; x >= 0; x--){
       printf("%c", str[x]);
    }
}
int main() {
    int value;
    scanf("%d", &value);
    binaer(value);
    return 0;
}
Input: 16
Output: 00001000000000000
 
    