/**************************************************** Description: This program converts an unsigned number in base 10 to base 2. Input: base 10 integer Output: binary integer *****************************************************/ #include #include main() { int base10; char binary[12]; char b10_b2(*char , int ); /** prompts user **/ printf("Type in an unsigned base 10 number.\n"); scanf(" %d", &base10); printf("base 10 is %d .\n", base10); /** echoes to screen, then sends value of base10 and address of binary to function **/ b2_b10(base10, binary); printf(" %d in base 10 is %s in base 2.\n", base10, binary); /** returns value of base 10 number in base 2 **/ } /*-----------------------------------------------------*/ /* Function name: b10_b2 */ /* Description: translates unsigned base 10 integer */ /* to unsigned binary integer */ /* Input parameters: address of binary integer and */ /* value of base 10 integer */ /* Output parameters: binary integer */ /* Return Value: binary value of given base 10 number */ /*-----------------------------------------------------*/ char b10_b2(char *binary, int base10) /**receives value of base 10 and address of binary **/ { int power=1, i = 12, bit; *binary[i] = base10 % 2; base10 /= 2; while (base10 > 0) { *binary[i--] = base10 % 2; base10 /=2; /** translates decimal to binary**/ } /** returns binary value of decimal to main **/ return (*binary); }