Originally Posted by
brandones
Got the code working. There were quite a few problems, including some basic mathematical ones. Thank you for the help!
Code:
printf("%d", x<0);
x<0 ? (x=-x) : x;
for(y=14; y>-1; y--){
int z = x-(pow(2, y));
z<0 ? printf("0") : printf("1");
x = (z<0 ? x : z);
Congrats on getting it working... Here's a complete solution in 20 lines...
Code:
#include <stdio.h>
int main (void)
{ char binary[33] = {0};
unsigned int number;
int x = 0;
printf("Enter a number from 0 to 4294967295 : ");
scanf("%u", &number);
while(x < 32)
binary[x++] = '0';
do
binary[--x] = (number & 1) + '0';
while ( (number /= 2) > 0 );
printf("32bit binary : %s\n\n", binary);
return 0; }