kainjow's solution is interesting, but is only good for values of num less than 2^11 and greater than or equal to 0. Above 2^11 bin will overflow and unfortunate things will start happening. For negatives I'm not sure what the result will be, but I don't think it will be the 2s complement representation. The positive part is that you can print the result with %d and the number will "look" binary.
I'm not sure if this was precisely what you were after or not. It's certainly an interpretation of your original question. I had a different one (that you just want to display an int in its binary representation). Since integers are stored in binary anyway and you're using a binary computer, you can take advantage of that and just print based on each bit being set. This was what I came up with. it may not be the most optimal, but should work.
Code:
#include <stdio.h>
void printbinary(int);
int main(int argc, char *argv[]) {
int number=20343;
printbinary(number);
}
void printbinary(int number) {
int x;
for(x = 31;x>=0;x--) {
if((number & (1 << x)) != 0) {
printf("1");
} else {
printf("0");
}
}
printf("\n");
}
This could be adapted to store to a char[33] for later use pretty easily.
-Lee
P.S. I guess it says something about kainjow's mindset and my own, being that we just assumed you wanted C/C++/Obj-C, mine leaning towards C than C++ due to the printf rather than cout. If you are trying to do this in a language that isn't easily adapted to from C, let us know.
P.P.S. This assumes 32-bit integers. that might be a bad assumption. 8*sizeof(int) could be substituted as needed for the bit-width of an int.