Question: Computer Science: Assembly Language for x86 Processors Conversion_between_Binary_and_Decimal I have to make two functions, int BinToDec(char* s) and char* DecToBin(int n). Write a C++ program
Computer Science: Assembly Language for x86 Processors
Conversion_between_Binary_and_Decimal
I have to make two functions, int BinToDec(char* s) and char* DecToBin(int n).
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
// ==============================================================
// Function: BinToDec
// 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: A decimal integer value calculated from s
// ==============================================================
int BinToDec(char* s);
// ==============================================================
// Function: DecToBin
// Description: 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);
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().
* For BinToDec(),
1. Multiplication complexity of O(n) is required============
2. Using Horner's method is suggested
* For DecToBin(),
1. Correctly using memory to return char* is required
2. The method of dividing by 2 and taking remainders reversely is suggested
Then you call two functions in main() like this:
while (...)
{
// Show menu and read case action
... ...
switch (n)
{
case 1: // How to call BinToDec()
{
// Prompt and Read input
// Call BinToDec()
// Output result
}
case 2: // How to call DecToBin()
{
// Prompt and Read input
// Call DecToBin()
// Output result
}
default: // Check others
{
... ...
}
}
}
Also, don't use OOP based class/object feature, either a standard string or your created one. You must use C-string.
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
