Answered step by step
Verified Expert Solution
Question
1 Approved Answer
I am trying to add line of codes into the code program below >>> what I need to be add is to make this code
I am trying to add line of codes into the code program below >>> what I need to be add is to make this code program to determine when an overflow exsistes or tell that there is no overflow.
extra more details on the provided pic...
code program;
#include
using namespace std;
char change(char p)
{
if (p == '0')
{
return '1';
}
else
{
return '0';
}
}
void OneTwoComplements(string binary,int n)
{
string oneComp, twoComp;
int i;
oneComp = twoComp = "";
for (i = 0; i
{
oneComp += change(binary[i]);
}
int p;
twoComp = oneComp;
for (p = n - 1;p >= 0;p--)
{
if (oneComp[p] == '1')
{
twoComp[p] = '0';
}
else
{
twoComp[p] = '1';
break;
}
}
if(p == -1)
{
twoComp = '1' + twoComp;
}
cout
cout
}
int main()
{
string binary;
int n;
cout
cin>>n;
cout
vale. 4. Program output: (a) The program should notify the user if an overflow occurs. An overflow occurs when the decimal value does not fit within the max/min (magnitude) range of the l's comp and 2's comp Binary number size. (b) If an overflow occurs, the program should notify the user and end the program. (c) Otherwise, if no overflow occurs, the program should notify the user that.no overflow occurs and display the l's comp and 2's comp Binary in the specified bit size) cin>>binary;
cout
OneTwoComplements(binary,n);
return 0;
}
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started