Write a Java or CC program to convert a base10 number to a b

Write a Java or C/C++ program to convert a base-10 number to a base-2 number. The following input should be tested:

Logic should split the number into integer and float then divide by 2 for the int concatenating into a string of 10000000 with the final remainder being 1 concatenated to the front. The float would be multiplied by 2 then 1 would be subtracted until you get 0. The two strings would be concatenated at the end to form something like 10000.000001.

1) 12
2) 12.6875

3) .6875

Solution

Code to convert base-10 number (decimal) to a base-2 number(binary)

#include <stdio.h>

int main()

{

long int dec, rem,quo;

int binary[100], x=1, y;;

printf(\"Enter a base-10 number (decimal value):\");

scanf(\"%d\", &dec);

quo = dec;

while(quo != 0)

{

binary[i++] = quo % 2;

quo = quo/2;

}

printf(\" equivalent base-2(binary) value of base-10 decimal %d is:\", dec);

for (y = x-1; y>0; y--)

printf(\"%d\", binary[y]);

return 0;

}

Enter a base-10 number (decimal value): 12

equivalent base-2(binary) value of base-10 decimal 12 is 1100

Enter a base-10 number (decimal value): 12.6875

equivalent base-2(binary) value of base-10 decimal 12.6875 is 1100.1011

Enter a base-10 number (decimal value): .6875

equivalent base-2(binary) value of base-10 decimal 6875 is is 0.1011

Write a Java or C/C++ program to convert a base-10 number to a base-2 number. The following input should be tested: Logic should split the number into integer a

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site