Decimal to Binary Conversion program
Hello, I wrote this program for my Intro to Digital Systems class to convert a base 10 number into a Binary base 2 number string. It works perfectly except for some numbers it slams a number in front of it. On linux this number is -1073742772. Such a number is 60.
Code:
#include <stdio.h>
int main()
{
int input=0;
int count=0;
int binary_backwards[32];
int binary_string[32];
int i=0;
int j=0;
printf("Enter a base 10 positive number to convert to binary:");
scanf("%i", &input);
while(input >0 && count<32)
{
binary_backwards[count] = input %2;
input /=2;
count++;
}
while(count >-1)
{
binary_string[i]=binary_backwards[count];
count--;
i++;
}
while(j<i)
{
printf("%i", binary_string[j]);
j++;
}
return 0;
}
Anyone have any ideas why this is happening?