Write C expressions that evaluate to 1 when the following conditions are true and to 0 when they are false. Assume x is of type int. Any bit of x equals 1. Any bit of x equals 0. Any bit in the least significant byte of x equals 1. Any bit in the most significant byte of x equals 0. Your code should follow the bit-level integer coding rules (page 128), with the additional restriction that you may not use equality (==) or inequality (!=) tests.

Respuesta :

Answer:

Check the explanation

Explanation:

#include <stdio.h>

#include <stdlib.h>

//function to print a message

static void printMessage(char *msg)

{

printf("%s\n", msg);

}

//perform option A

int perform_A(int x)

{

//return true if any bit of x is equal to 1

return !!x;

}

//perform option A

int perform_B(int x)

{

//return true if any bit of x is equal to 0

return !x;

}

//perform option C

int perform_C(int x)

{

//return true if least significant bit is 1

return !!(x & 0xFF);

}

//perform option D

int perform_D(int x)

{

//return true if most significant bit is 0

return !!(~x & 0xFF);

}

//the main function

int main(void)

{

//set the integer

int input = sizeof(int) << 3;

//declare the test values

int onebitis1 = ~0;

int onebitis0 = 0;

int onebitLeast1 = 0xFF;

int onebitMost0 = 0xFF << (input - 8);

(perform_A(onebitis1)) && (printf("A return True\n"));

(perform_B(onebitis0)) && (printf("B returns True\12"));

(perform_C(onebitLeast1)) && (printf("C returns True\n"));

(perform_D(onebitMost0)) && (printf("D returns True\n"));

//to wait for a key press

getchar();

return 0;

}

Kindly check the attached image below to see the output.

Ver imagen temmydbrain

Following are the program to the given expression:

Program:

#include <stdio.h>//header file

#include <stdlib.h>//header file

static void printMessage(char *m)//defining a method printMessage that takes character type pointer variable

{

printf("%s\n", m);//print messsage

}

int p_A(int x)//defining method p_A that takes one integer variable in the paramter

{

return !!x;//return value

}

int p_B(int x)//defining method p_B that takes one integer variable in the paramter

{

return !x;//return value

}

int p_C(int x)//defining method p_B that takes one integer variable in the paramter

{

return !!(x & 0xFF);//return value

}

int p_D(int x)//defining method p_D that takes one integer variable in the paramter

{

return !!(~x & 0xFF);//return value

}

int main()//defining main method

{

int i = sizeof(int) << 3;//defining integer variable that uses the sizeof method that check integer variable value

int ob1 = ~0;//defining integer variable that initilizes with the value

int ob0 = 0;//defining integer variable that initilizes with the value

int obL1 = 0xFF;//defining integer variable that initilizes with the value

int obM0 = 0xFF << (i - 8);//defining integer variable that initilizes with the value

(p_A(ob1)) && (printf("A return True\n"));//calling method that checks and print value

(p_B(ob0)) && (printf("B returns True\12"));//calling method that checks and print value

(p_C(obL1)) && (printf("C returns True\n"));//calling method that checks and print value

(p_D(obM0)) && (printf("D returns True\n"));//calling method that checks and print value

return 0;

}

Program Explanation:

  • Defining header file.
  • After defining the header file, five method, "printMessage, p_A,p_B, p_C, and p_D".
  • Inside the "printMessage" it takes one character type pointer variable, and in other method it takes one integer variable in the method, and calculates the values.    
  • In the next step, a main method is declared that defines the integer variable that call the method and prints its return value.

Output:

Please find the attached file.

Find out the more informatin about the Operator here:

brainly.com/question/16102843

Ver imagen codiepienagoya