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

It is often useful to describe a complex system made up of several units, each o

ID: 3846776 • Letter: I

Question

It is often useful to describe a complex system made up of several units, each of which is individually and independently buy or available. This system could be a manufacturing plant where each unit is a particular machine. It is important to identify which machines are busy and which are available, so that work can be assigned as needed. We can keep track of 16 machines with a 16-bit binary pattern, where a bit is 1 if the machine is free and 0 if the machine is busy. a) Write a function to count the number of busy machines for a given busyness pattern. The input of this function will be a bit pattern (which can be written as an integer variable) and the output will be an integer corresponding to the number of busy machines. b) Write a function to take two busyness patterns and determine which machines have changed state, that is, gone from busy to idle, or idle to busy. The output of this function is simply another bit pattern with a 1 in each position corresponding to a machine that has changed its state. C) Write a program that reads a sequence often busyness patterns (as hexadecimal numbers) from the keyboard and determines the average number of busy machines and the average number of machines that change state from one pattern to the next (as floating point numbers). Use the functions you developed in a) and b) to write your program. Comments count! Remember to use them.

Explanation / Answer

Please find the below solution for the above questions. I have used java as a coding language.

1. One integer value in a form of "0" and "1" as input.

public static int CountBusyMachines(int num){
       // variable to store the count of busy machine
       int count =0;
       int n =num;
       int res = 0;
       while(n !=0){
           res = n%10; // this will provide the last most digit of the integer input
           if(res == 1){
               count++; // Incrementing count if the digit is 1
           }
           n=n/10; // dividing the n by 10 to shift the integer to one digit right
       }
       return count;
   }

2. public static int stateChanged(int a, int b){
       int res1 = 0;
       int res2 = 0;
       int n = a;
       int m = b;
       String f = new String();
       while(n!=0 && m !=0){
           res1 = n%10;
           res2 = n%10;
           if(res1 == res2){
               f = f+"1";
           }
       }
       int s = Integer.parseInt(f);
       //reverse the s and return.
       int r = 0;
       String k = "";
       while(s!=0){
           r = s%10;
           k=k+r;
           s=s/10;
       }
       int res = Integer.parseInt(k);
       return res;
      
   }

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote