BIT CODES.
Create a program that will ask the user to enter a decimal value (1-999999) then display its
corresponding binary numbers. Repeat this process until the value entered is equal to 0.
Use the following Function Prototype:
void BinCodes(int value);
Sample Input/Output:
Enter a Decimal: 35
Binary: 100011
Enter a Decimal: 184
Binary: 10111000
Enter a Decimal: 0
Forum Guide wrote:
Don't post homework questions
Those questions are for you to work out, so that you will learn from the experience. It is OK to ask for hints, but not for entire solutions.
http://www.wikihow.com/Convert-from-Decimal-to-Binary

There's an algorithm here on how to do it. I did the same homework problem a long time ago.
Last edited on
I just did your homework in less than 12 minutes.

 ``123456789101112131415161718192021222324252627282930`` ``````#include #include #include void BinCodes(int value){ enum boolean {FALSE, TRUE}; boolean condition = TRUE; int rollover_value = value; std::string str1; while(condition){ str1.push_back(rollover_value % 2); rollover_value = rollover_value / 2; if(0 == rollover_value){ condition = FALSE; } } for(int i = 0; i < str1.length();i++){ str1[i] += 48; } std::reverse(str1.begin(),str1.end()); //http://www.cplusplus.com/forum/general/110608/ std::cout << "Binary: " << str1 << std::endl; } int main(){ int user_input; std::cout << "Enter a number: "; std::cin >> user_input; BinCodes(user_input); }``````
Last edited on
Thank u sir !
Topic archived. No new replies allowed.