Plan 2 theme
# include & ltstdio.h & gt

# include & ltstdlib.h & gt

//The function is to calculate the complement of an integer from high to low in the lower two bytes according to the requirements of the topic.

int binary(int high,int low,int number){

int bit count = 0; //Number of digits from high to low

int data = 0;

int mid = 0;

char p[2]= { 0 };

for(int I = 0; I< 16; i++){

mid = mid & lt& lt 1;

If (I & lt=( 15- low)&I & gt=( 15- high)) mid+=1;

}

//Extract high to low * * high-low+1 digit from number and store it in number.

Number = Number & ampmid

//Take out the lowest byte of $ number and put it in p[0] for later calculation.

P[0]= number & amp0xFF

//Take out the penultimate byte of number and put it in p[ 1] for later calculation.

p[ 1]=(number & gt; & gt8)& amp; 0xFF

printf( "\n%d %d ",(int)p[ 1],(int)p[0]);

//Calculate the number of digits of this number and put it in bitcount.

Bitcount= (height)+1;

printf( "\n%d ",bit count);

//If the higher order is less than 8, all the bits of the number are in p[0].

If (high & lt8)

{

data = p[0]& gt; & gt low;

}

else if(low & gt; 7) // If the low order is greater than 7, all the bits of the number are in p[ 1].

{

data = p[ 1]& gt; & gt (low-8);

}

other

{

data = p[ 1]& lt; & lt(8- low);

data+=(p[0]& gt; & gt low);

}

//If the number is negative, calculate the original code according to the principle of "complement = complement of the original code+1".

if( 1 = =(data & gt; > (bit count-1))

{

Data = data < < (17 bit count);

Data = Data & amp0xFFFF

Data = data & gt& gt( 17 bit count);

Data = data-1;

Data = data < < (17 bit count);

Data = ~ data;

Data = Data & amp0xFFFF

Data = data & gt& gt( 17 bit count);

Data = 0- data;

}

Return data;

}

int main()

{

int high = 0;

int low = 0;

int number = 0;

Int data;

Printf ("\ nPlease enter a number. \ n ");

//Enter any integer as a number in the memory.

Scanf("%d ",&);

//Output the number just now to the screen in hexadecimal format.

Printf ("\ nThe number is 0x%x", number);

//Requires the user to input high and low bits, with the high bits separated by spaces not greater than 15 and the low bits not less than 0.

Printf ("\ nPlease enter a high value and a low value (16 > High & gt low & gt=0): ");

Scanf("%d %d ",& high & low);

//The high position must be greater than the low position.

If (high < = low)

{

printf(" Error ");

return- 1;

}

//Call the conversion function

Data = binary (high, low, number);

//Output conversion function

printf("\ndata:%d\n ",data);

}