Decimal to Binary Converter
i am writing a function that will accept an integer as a parameter, convert it into a binary number (use a string to hold this) and return the binary string to the caller. The format of the binary number should be such that it is easy to read, i.e. split into blocks of 4. For example, the value 83247 would be output as a 32 bit number:
0000 0000 0000 0001 0100 0101 0010 1111
this is the code so far
Code:
#include <stdio.h>
#include <stdlib.h>
#include <conio.h>
int main()
{
int input=0;
int count=0;
int binary_backwards[32];
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)
printf("%d", binary_backwards[count]) ;
system("pause");
}
it works fine but i can see how to make it out put the extra zeros and put spaces after every 4.