#include
int main()
{
unsigned int a, b, c, d;
unsigned int f;
/* Print header for K-map. */
printf(" bc ");
printf(" 00 01 11 10 ");
printf(" ______________ ");
/* row-printing loop */
for (a = 0; 2 > a; a = a + 1) {
printf("a=%u | ", a);
/* Loop over input variable b in binary order. */
for (b = 0; 2 > b; b = b + 1) {
/* Loop over d in binary order.*/
for (d = 0; 2 > d; d = d + 1) {
/* Use variables b and d to calculate *
* input variable c (iterated in *
* Gray code order). */
/* CALCULATE c HERE. */
/* Calculate and print one K-map entry *
* (function F(a,b,c) ). */
/* INSERT CODE HERE. */
}
}
/* End of row reached: print a newline character. */
printf(" ");
}
return 0;
}
The above program provides some initial code to generate a 3-variable K-Map for a 3-variable Boolean function. For example, for function F(a,b,c) = ab + b'c' the program should print the following:
Complete the program above. For your portion of the code at "CALCULATE c HERE", you must begin by ensuring that the variable c follows Gray code order and runs from 0 to 1 when b=0, but from 1 to 0 when b=1. At "INSERT CODE HERE", you must then calculate the function F(a,b,c) = (a'+b') (a+b'+c) (b+c'). Do not otherwise change the program. For full points, use C's bitwise operators (&, |, ^ and ~) to perform both of these calculations.
Screenshot code
Screen shot output of program; that is, the K-Map for F(a,b,c) = (a'+b') (a+b'+c) (b+c').
Hint 1: You may find it helpful to verify the output on a paper version of the K-map.
Hint 2: Remember that bitwise operators operate on the entire pattern of 32-bits (here the bit pattern corresponds to unsigned int). It might be useful for you to print the output F to see for yourself what is happening with the bits. Then, before having your code printing F, you must 'discard' all bits other than the 1's position (one way would be to use an & operation with an appropriate value).
Again, you may not hardcode the K-map or change the program other than as specified. Your program must compute F(a,b,c) = (a'+b') (a+b'+c) (b+c').