I was looking at the other things on this site and noticed the challenges. The dectobin problem looked easy so I jumped on it... it took me no more than two minutes to get the basic algorithm working. Then I spent a few more minutes tweaking in the output formatting.
I didn't look at the solution yet, but I am sure it is very similar to what I have...
Well, here's my solution (for those who have an interest):
(note: I have only tested this on MSVS.NET 2003)Code:#include <iostream> int main(int argc, char* argv[]) { if (2>argc) { std::cout << "usage: dectobin number\nwhere: number is a 32 bit decimal in the range 0 - 4294967295" << std::endl; return 1; } int num = 0; num = atoi(argv[1]); for (int i=31; i >=0; --i) { if (num>>i &0xffffffff) { if (num>>i &0x01) std::cout << 1; else std::cout << 0; if (i % 4 == 0) std::cout << " "; } } return 0; }
I suppose I should go do the others now... though some of them look a bit more time consuming than this one
Rog