Working on a homework assignment for class, part of the assignment has us converting from base ten to binary, and representing the binary number as an array of type char. For some reason it's not computing the right most bit. Any help would be appreciated.
#include <stdlib.h>
#include <stdio.h>
xtractmsg(int a)
{
int rem,i,b,j,quotient;
char binaryNumber[16];
for(i = 0; i <= 16; i++){
if(a == 0)
binaryNumber[i]='0';
else{
rem = a % 2;
if(rem == 0)
binaryNumber[i]='1';
else
binaryNumber[i]='0';
a=a/2;
}
}
for(j=15; j>=0;j--)
printf("%c,%d",binaryNumber[j]);
}
input is ten, output is 0000000000000101.
printfcall.