Q:

converting decimal to 32 bit binary

Hi I have been giving an assignment for my programming in C class and a question im stuck on is this. 
"Prompts the user to enter a valid integer between 0 and
2147483647 inclusive, and then displays the converted
value as a 32-bit binary number with 1 space separating
each 8-bits in the binary value. If an invalid number
is entered (i.e < 0 or > 2147483647)"
it wants me to output the binary in 32 bit format such as 00000000 00000000 00000000 00011111 =31 with all of the 0's and spacing between each set of 8 and I am stuck. 
 printf("enter a valid integer between 0 and 2147483647\n");
                 scanf("%d",&decimal);
                 fflush(stdin);
                 if (decimal>0||decimal<2147483647)
                   {while (decimal!=0)
                   {
                          remainder = decimal%2;
                          binary=(remainder*place)+binary;
                          decimal=decimal/2;
                          place=place*10;}
                   printf("%d",binary);}

this kinda works until the input is over 1000 then its gets messed up. unsure why as well.

A:

You know that numbers are stored in binary in memory, right? So you can just examine each bit, one by one, and print out the result as you go:
You can examine the bits using bitwise operators. You can create the binary number 1000 0000 0000 0000 from the number 1 by left-shifting the number 31 places: 1<<31. You can then check if your number has the 32nd bit set with a  bitwise-and: (1<<31) & decimal. If the result is zero, then that bit was not set. If the result is non-zero, then the bit was set.
Assuming the single-bit value (this is usually called a mask) is stored in an unsigned int, you can check the 31st bit by right-shifting it once:
unsigned int mask = 1 << 31; // mask for 32nd bit
mask = mask >> 1; // move mask to 31st bit
if (mask & decimal != 0) {
  // 31st bit is set
}
else {
  // not set
}

Using an unsigned int is very important. If you use a normal (signed) int, then the >> operator has a different behavior. For unsigned numbers, when shifting right, the left-hand-side is padded with zeros. For signed numbers, the left-hand-side is instead padded with whatever value (0 or 1) was in the highest bit. So, if you had the signed binary value 1000 0000 0000 0000 and you shift it right 1 (signed_mask >> 1), then you would end up with 1100 0000 0000 0000 rather than 0100 0000 0000 0000.
Here is a working example:
#include <stdio.h>

int main(int argc, char *argv[]) {
    int i, j, decimal;
    printf("enter a valid integer between 0 and 2147483647\n");
    scanf("%d",&decimal);
    fflush(stdin);
    // all signed integers are <= 2147483647, so just check if it's positive
    if (decimal>0) { 
        // create a "mask" to look at the 32nd bit
        // note that we use an unsigned mask!
        // this is important because we don't want
        // sign-extending when we shift to the next bit.
        unsigned int mask = 1<<31;
        for (i=0; i<8; i++) {
            for (j=0; j<4; j++) {
                // check current bit, and print
                char c = (decimal & mask) == 0 ? '0' : '1';
                putchar(c);
                // move down one bit
                mask >>= 1;
            }
            // print a space very 4 bits
            putchar(' ');
        }
        putchar('\n');
    }
    return 0;
}

Note the condition decimal>0||decimal<2147483647 in your code is always true. I think you meant to use &&, not ||. However, 2147483647 is the maximum value for a signed 32-bit integer (231-1), so it doesn't actually make sense to check the upper bound.

