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]
2 years 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]2 years 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
Computers in a medical office should be protected by which of the following security tools?
Verizon [17]
<span> it is necessary to maintain your computer on a regular basis. .... Remember these key points when recommending the Internet to a patient

Hope it helps.
</span>
8 0
4 years ago
Read 2 more answers
Soft skills are similar to personality traits like being compassionate, having patience, and working well in groups.
ikadub [295]

The answer is A. True


Because soft skills are:

1) Good communication skills

2) Team work

3) Positive attitude

4) Self confidence

5) Ability to learn from criticism

6) problem solving skills

7) patience

8) leadership quality


I hope the answer is clear

8 0
4 years ago
Read 2 more answers
there are four stage of the product life cycle. during which of these stages do you think is the best time for a company to purc
Alisiya [41]

Maturity Stage – During the maturity stage, the product is established and the aim for the manufacturer is now to maintain the market share they have built up. This is probably the most competitive time for most products and businesses need to invest wisely in any marketing they undertake. They also need to consider any product modifications or improvements to the production process which might give them a competitive advantage. i think this would be the best time for the company to purchase an emerging technology.

7 0
3 years ago
Read 2 more answers
Explain LCD and give two example​
Pani-rosa [81]

Answer:

LCD means least common denominator• a "Common Denominator" is when the bottom number is the same for the fractions.

Explanation:

3 0
3 years ago
Read 2 more answers
A ____________ is the intersection of a column and row in an excel spreadsheet.
kogti [31]

Answer:

a cell is the intersection of a column and row in an excel spreadsheet.

4 0
3 years ago
Other questions:
  • What causes the lens of the camera to extend or retract
    6·2 answers
  • Which of the following statements is correct? A. The columns will be listed in the results in the same order they are stored in
    7·1 answer
  • TRUE OR FALSE!!!!!
    6·2 answers
  • Can you give me a long list of kid's cartoons
    8·2 answers
  • In a microsoft word document, what is the amount of space that appears between paragraphs called?
    14·1 answer
  • What does it mean to have an "online presence"? Explain how it can affect a job search?
    11·1 answer
  • While these two approaches have similarities in terms of the topics they address, ________ will cover broad IT management topics
    7·1 answer
  • A SmartArt graphic consists of two parts: the SmartArt graphic itself and a(n) ____ pane.
    5·1 answer
  • Which part of project management involves determining the required materials?
    7·2 answers
  • Your online actions can have real- world consequences. True or false?
    7·2 answers
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!