1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
siniylev [52]
1 year ago
15

You have to write a program that will read a number followed by a series of bit operations from a file and perform the given ope

rations sequentially on the number.
The operations are as follows:
set(x, n, v) sets the nth bit of the number x to v
comp(x, n) sets the value of the nth bit of x to its complement (1 if 0 and 0 otherwise)
get(x, n) returns the value of the nth bit of the number x
The least significant bit (LSB) is considered to be index 0.
Input format: Your program will take the file name as input. The first line in the file provides the value of the number x to be manipulated. This number should be considered an unsigned short. The following lines will contain the operations to manipulate the number. To simplify parsing, the format of the operations will always be the command name followed by 2 numbers, separated by tabs. For the set(x, n, v) command, the value of the second input number (v) will always be either 0 or 1. For the comp(x, n) and get(x, n) commands the value of the second input number will always be 0 and can be ignored. Note that the changes to x are cumulative, rather than each instruction operating independently on the original x.
Output format: Your output for comp and set commands will be the resulting value of the number x after each operation, each on a new line. For get commands, the output should be the requested bit’s value.
Example Execution:
For example, a sample input file "file1.txt" contains the following (except the annotation comments):
5 ---------------------------------# x = 5
get 0 0 -------------------------# get(x, 0), ignoring second value (0)
comp 0 0 ----------------------# comp(x, 0), ignoring second value (0)
set 1 1 --------------------------# set(x, 1, 1)
The result of the sample run is:
$ ./first file1.txt
1
4
6
Computers and Technology
1 answer:
tatuchka [14]1 year ago
8 0

The program what will read a number followed by a series of bit operations from file and perform the given operations sequentially on the number is given below.

<h3>What is an operation in computer science?</h3>

An operation, in mathematics and computer programming, is an action that is carried out to accomplish a given task.

There are five basic types of computer operations:

  • Inputting,
  • processing,
  • outputting,
  • storing, and
  • controlling.

<h3>What is the requested program above?</h3>

#include <stdio.h>

#include <fcntl.h>

int main(int argc, char *argv[])

{

  int number, n, v, temp;

  char line[25], fun[10];

  FILE *f = fopen(argv[1], "r");

 

  fgets(line, 24, f);

  sscanf(line, "%d", &number);   //reading the number

  while( fgets(line, 24, f) )

   {

      sscanf(line, "%s %d %d", fun, &n, &v); //reading the commands

      switch(fun[0])           //checking which command to run

      {

          case 'g':    temp = 1;

                      temp = temp<<n;   //shifting for getting that bit

                      printf("%d\n",(number&temp)&&1);

                      break;

          case 's':   temp = 1;

                      temp = temp<<n;   //shifting for setting that bit

                      if(!v)

                      {

                          temp = ~temp;

                          number = number & temp;

                      }

                      else

                      {

                          number = number | temp;

                      }

                      printf("%d\n",number);

                      break;

          case 'c':   temp = 1;

                      temp = temp<<n;   //shifting for complimenting that bit

                      number = number ^ temp;   //xor to complement that bit

                      printf("%d\n",number);

                      break;

          default:printf("not defined");

      }

  }

  return 0;

}

Execution and Output:

terminal-> $ gcc -o first first.c

terminal-> $ ./first file1.txt

1

4

6

Learn more about programs at;
brainly.com/question/16397886
#SPJ1

You might be interested in
Perform algorithm time measurement for all three quadratic sorting algorithms for Best Case (already sorted), Average Case (rand
Kaylis [27]

Answer:

Experiment size : 50,000

==================================

Selection sort :

---------------------------------------------------------

Worst case : 0.162

Average case : 0.116

Best case : 0.080

Insertion sort :

---------------------------------------------------------

Worst case : 0.162

Average case : 0.116

Best case : 0.080

Bubble sort:

--------------------------------------------------------

Worst case : 0.211

Average case : 0.154

Best case : 0.117

Experiment size : 100,000

==================================

Selection sort :

---------------------------------------------------------

Worst case : 0.316

Average case : 0.317

Best case : 0.316

Insertion sort :

---------------------------------------------------------

Worst case : 0.316

Average case : 0.317

Best case : 0.316

Bubble sort:

--------------------------------------------------------

Worst case : 0.482

Average case: 0.487

Best case : 0.480.

Experiment size : 200,000

==================================

Selection sort :

---------------------------------------------------------

Worst case : 1.254

Average case : 1.246

Best case : 1.259

Insertion sort :

---------------------------------------------------------

Worst case : 1.254

Average case : 1.246

Best case : 1.259

Bubble sort:

--------------------------------------------------------

Worst case : 1.990

Average case : 2.009.

Best case : 1.950

Explanation:

[NB: since it is very long there is the need for me to put it it a document form. Kindly check the doc. Files. The file A is the sort Analysis.Java file and the file B is the sort.Java file].

The concept of algorithm time measurement strictly depends on the following;

=> The measurement of time, space or energy on different sizes.

=> Plotting of the measurements and characterizing them.

=> Running or implementation of the algorithm.

Programming language such as Java can be used in accessing the operating system clock and Java had two static methods.

KINDLY CHECK BELOW FOR THE ATTACHMENT.

Download doc
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> doc </span>
<span class="sg-text sg-text--link sg-text--bold sg-text--link-disabled sg-text--blue-dark"> doc </span>
5 0
3 years ago
Which program will have the output shown below?
Nutka1998 [239]

Answer: Python

Explanation: All I know is that the programming language is Python.

8 0
2 years ago
Read 2 more answers
Suppose that the splits at every level of quicksort are in the proportion 1 − α to α where 0 &lt; α ≤ 1/2 is a constant. Show th
Lady_Fox [76]

Answer:

Explanation:

The minimum depth occurs for the path that always takes the smaller portion of the

split, i.e., the nodes that takes α proportion of work from the parent node. The first

node in the path(after the root) gets α proportion of the work(the size of data

processed by this node is αn), the second one get (2)

so on. The recursion bottoms

out when the size of data becomes 1. Assume the recursion ends at level h, we have

(ℎ) = 1

h = log 1/ = lg(1/)/ lg = − lg / lg

Maximum depth m is similar with minimum depth

(1 − )() = 1

m = log1− 1/ = lg(1/)/ lg(1 − ) = − lg / lg(1 − )

4 0
3 years ago
What is a functionalist perspective of cell phones, internet and personal computers?
Sedbober [7]
<span>As these technologies are rapidly evolving a functionalist would say that they unbalance the equilibrium of the social state, and is therefore undesirable as there is more interaction and adaptation of habits from other societies. But they also say that it's not a good thing to change immediately because it might disrupt the society. Therefore it has to change slowly. </span>
3 0
3 years ago
describe briefly one scenario where records stored in a computer frequently need to be searched. state why the searches may be c
Gnoma [55]
Because the string is invalid or your source is not attached to your search engine.
4 0
2 years ago
Read 2 more answers
Other questions:
  • Hudson has to maintain confidential college data in a workbook. He needs two team members to help him update data in the specifi
    7·2 answers
  • Assume that nextWord is a String variable that has been given a String value consisting entirely of letters. Write some Java cod
    6·1 answer
  • What is the purpose of inserting SmartArt in a Microsoft Office program? (1 point)
    11·2 answers
  • What do you click to create a new presentation in noral view
    12·1 answer
  • Given the function definition below, what is the effect of thecall:
    7·2 answers
  • "Managers and department heads across the nation strategize on a weekly, if not daily, basis. For the past three quarters, telep
    6·1 answer
  • Which of the following can be represented by a single binary digit?
    14·1 answer
  • 1. Discuss the pros and cons of human-computer interaction technology?
    6·1 answer
  • (a) Write a program which calculates and displays the obtained marks, percentage in six subjects and assigns grades based on per
    6·1 answer
  • If you walked into a room containing three computers and were told one of them was infected with malware, how would you determin
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!