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
Assume that the string oldSeq has been properly declared and initialized and contains the string segment. Write a code segment t
son4ous [18]

String oldSeq="1100000111";

String segment="11";

String newSeq=oldSeq.replaceFirst(segment, "");

7 0
3 years ago
MICR is an input or output devices
Nataly [62]

Explanation:

If a device is putting data into the computer in the form of text, sound, images, button presses etc. then it is an input device, if the device is outputting things from the computer such as sound, movement, printing, images etc., then it is an output device. ... Therefore it is an input device.

8 0
3 years ago
1. A thesaurus is best used to _____________.
NemiM [27]
1. The correct answer is <span>B. help find a word that means the same or a similar definition as another word. Thesaurus is a kind of dictionary that contains synonyms (words with the same or similar meaning) or antonyms (words with opposite meaning). It doesn't contain definitions, but only related words. To find definitions, you would have to look in a dictionary.

2. </span><span>Using synonyms can help make your writing more interesting. A text can often become oversaturated with the same word repeated many times, at the expense of nice flow and style. So, sometimes it is better to come up with adequate synonyms and use them. By looking for synonyms, we can find a more vivid and imaginative word than the one we had in mind.

3. A table can help us organize thoughts and ideas. When put into a table, information and thoughts become easily accessible and comprehensible. It helps us organize them, deriving the essence and the most important parts out of a text. A table is, basically, a way to visualize thoughts, which also makes them easier to memorize.

4. The "view side by side" feature would be useful in editing or comparing two different documents, so we don't have to minimize and maximize them all the time. We can create tables, search for words, or use the "search and replace" function perfectly well without using the "view side by side" feature. But when it comes to editing and comparing, it is extremely helpful to see both documents at the same time and compare them directly.</span>
3 0
3 years ago
___ is a career discipline focusing on helping companies use computer technology effectively.
pickupchik [31]

Answer:

A (information technology)

Explanation:

4 0
2 years ago
The was the series of events that marked the start of the Information Age
Artyom0805 [142]

The Information Age was the series of events that marked the start of the Information Age

Further Explanation:

I would simply put digital revolution as the gradual shift of technology from analogue to what is now known as digital technology. This sort of a paradigm shift began somewhere between the late 1950s to the late 1970s and has continued to this day. In a span of only 50 years, digital revolution has advanced tremendously and it is yet to start. The Digital Revolution marked the beginning of the Information Age.

The Information Age or the computer age as many would put it is what defines this shift. The invention of transistors, chips and the internet revolutionized the modern world and brought about the birth of information age. It is what connects us to the human civilization. Scientists capitalized on digital micro-miniaturization and as a result formed the Information Age. It is here with us and its sole existence has been embraced by billions of people worldwide.

Learn more about information age

brainly.com/question/10028333

brainly.com/question/10385855

#LearnWithBrainly

7 0
3 years ago
Other questions:
  • 1. Information integrity ensures that data can be modified only by appropriate mechanisms.
    9·2 answers
  • When a defendant pleads guilty to one offense just to have another offense dropped, this is what type of plea bargain
    14·2 answers
  • Two technicians are discussing fully charged battery voltage readings. technician a says that it should read approximately 12.6v
    8·1 answer
  • Compare the specialized and statistical functions in excel
    10·1 answer
  • Easy upgrade from windows xp to windows 7
    7·1 answer
  • Ron is creating building blocks in Word. How can he make the building blocks that he created available?
    8·2 answers
  • What is this car first to awnser is the brianliest
    5·2 answers
  • Modify theme in excel
    5·1 answer
  • Alguien me podria ayudar a hacer este codigo porfavor? en php Desarrolle el código que solicite los datos (desde teclado) Nombre
    10·1 answer
  • A flowchart meeting is a process where members of the team analyze the design piece-by-piece to make sure it meets requirements
    15·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!