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
You need to upgrade memory in a system but you don't have the motherboard documentation available. you open the case and notice
Harlamova29_29 [7]
<span>The three yellow slots probably indicate triple channeling, which means the board uses DDR3 DIMMs. To know for sure, remove a DIMM and look for the position of the notch on the DIMM.</span>
6 0
3 years ago
Jerry suspects that information about his internet usage was sent to external websites without his knowledge. He is wary about t
Leviafan [203]

Since advertisement and newsletters are filled in inbox of jerry. There is no external software to do scanning removing unnecessary mails such as advertisement and newsletter.

<u>Explanation:</u>

Best away or practice, jerry has to open each mail of advertisement and newsletter and unsubscribe the email address.

In future jerry should not click any link which comes in the inbox.

Once unsubscribe the newsletter and advertisements better to scan the computer any mail ware or spyware is attached on jerry laptop or workstation or pc.

There is no external web tool is available to unsubscribe in newsletter or advertisement for jerry mailbox.

3 0
3 years ago
A hydraulic lift has a mechanical advantage of 5. If the load weighs 350 N, what effort is required to lift the weight? Provide
Dmitrij [34]

If the load weighs 350 N, the effort that is required to lift the weight is 70 N

To answer the question, we need to know what mechanical advantage is.

<h3>What is mechanical advantage?</h3>

The mechanical advantage of the hydraulic lift M.A = L/E where

  • L = load and
  • E = effort.
<h3>Effort required to lift the weight</h3>

Making E subject of the formula, we have

E = L/M.A

Given that

  • M.A = 5 and
  • L = 350 N,

substituting the values of the variables into the equation, we have

E = L/M.A

E = 350 N/5

E = 70 N

So, the effort that is required to lift the weight is 70 N

Learn more about mechanical advantage here:

brainly.com/question/26440561

#SPJ1

7 0
3 years ago
Which manufacturing industry makes semiconductors that are used in a variety of systems?
aleksley [76]
Transportation equipment
7 0
3 years ago
Which of these conclusions supports the fact that Eclipse is categorized as an IDE?
Drupady [299]

Answer:

The user must specify the programming language he or she wants to use.

Explanation:

6 0
3 years ago
Other questions:
  • Cd-roms typically use the _______ filesystem type.
    11·1 answer
  • Command icons under the following file tab in its function
    14·1 answer
  • Write a program that uses these bounds and bisection search (for more info check out the Wikipedia page on bisection search) to
    8·1 answer
  • What is the smallest amount of information called?
    13·2 answers
  • Judy forgot where she saved a certain file on her computer. Therefore, she searches for all files with a .jpg file extension. Wh
    7·2 answers
  • What do you use the Pygame library for?
    6·1 answer
  • Which of the following statements about security in the network is true?
    15·1 answer
  • How to change my age on this app
    10·2 answers
  • Write a program that repeatedly reads in integers until a negative integer is read. The program keeps track of the largest integ
    9·1 answer
  • You suspect that a bad video driver is causing a user's system to randomly crash and reboot. Where would you go to identify and
    11·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!