/********************************************************************************************* * * Description: This program takes in a 4-bit unsigned base 2 number * and translates it into a decimal value. * * Input: A 4-bit unsigned base 2 number * * Output: States value of number in base 10. * *********************************************************************************************/ #include main() { int binary, decimal, threed, twod, oned; printf("Please type in a 4-digit 2s-complement number.\n"); /** prompts user **/ scanf("%d", &binary); printf("[%d]\n", binary); /** echoes input to screen **/ decimal = binary/1000*8; /** computes value of 2^3 position **/ threed = binary%1000; decimal = decimal + (threed/100)*4; /** computes value of 2^2 position **/ twod = (threed%100); decimal =decimal + (twod/10)*2; /** computes value of 2^1 position **/ oned = twod%10; decimal = decimal+oned; /** computes value of 2^0 position **/ printf("The integer you entered (%d) converts to \n", binary); printf("%d in base 10.\n", decimal); /** prints base 10 value of integer **/ }