Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. Read a value in two’scomplement notation from a file named input8.txt. 2. Con

ID: 3610917 • Letter: 1

Question

1.      Read a value in two’scomplement notation from a file namedinput8.txt.

2.      Convert the value fromtwo’s complement notation to decimal notation.

3.      Output tooutput8.txt the original two’s complementvalue and its equivalent decimal value.

           These steps must be repeated as long as there are values in theinput file.

           Function main() must read the binary number as an array ofcharacters and call function int comptodec(char *binary) that receives the 2’s complement number infree format (any number of bits) as a pointer to characters andreturns an integer that represents the corresponding decimalnumber. Function comptodec() must be able toprocess binary values of any length but main() must only displaydecimal values within the range -128…127. Values outside therange must be treated as overflow or underflow.

           

Explanation / Answer

#include #include #include using namespace std; int comptodec(char * binary) {    int decimal=0;    int i=1;    int bit;    if(binary[0] == '1')        decimal = -1;    while( binary[i] != '')    {        //cout