Question: Programming in C++ ( Visual Studio 2017 ) Conversion_between_Binary_and_Decimal I have to make two functions, int BinToDec(char* s) and char* DecToBin(int n). The purpose is
Programming in C++ ( Visual Studio 2017 )
Conversion_between_Binary_and_Decimal
I have to make two functions, int BinToDec(char* s) and char* DecToBin(int n).

The purpose is to make you understand the number system concept. So you have to manually implement the ideas without making use of some library function, like itoa(), atoi(), pow(), etc. that make the assignment meaningless. Only function allowed to use is strlen().
1. For BinToDec(),
- Multiplication complexity of O(n) is required
- Using Horner's method is suggested
2. For DecToBin(),
- Correctly using memory to return char* is required
- The method of dividing by 2 and taking remainders reversely is suggested
Then you call two functions in main() like this:

Also, don't use OOP based class/object feature, either a standard string or your created one. You must use C-string. Notice
1. The difference between a C-string and a char array. C-string is a zero-terminated char array
2. For a C-string, you can directly use it in cin and cout. Dont set a loop to input/output for each char
3. If not understood well, search online such as
- C strings and C++ strings at www.prismnet.com/~mcmahon/Notes/strings.html
- C-style strings in C++ at www.cplusplus.com/forum/beginner/73114/
4. Avoid using mixed cin>>someVar and get()/getline() in this assignment.
Conversion_between_Binary_and_Decimal (Chapter 1) Write a C++ program converting an 8-bit unsigned binary to its decimal and converting a positive decimal to its 8-bit binaries. You can create functions declared as :1 : // Description: This function converts an 8-bit binary integer to its decimal :// Parameter: s [IN]a C-string with 8-bit binary digits received :// Return: / Function: BinToDec A decimal integer value calculated froms int BinToDec (char* s); : // Function: DecToBin : // Deseription: This function converts a decimal integer to its binary bits :/ Parameter: n [IN]a decimal integer received, less than 256 // Return : A C-string with 8-bit binary digits calculated from n char* DecToBin(int n)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
