Menu
support@nursinghomework.org
+1 714-215-3097

(Solved) : Write Program Read Number Followed Series Bit Operations File Perform Given Operations Seq Q35595055

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

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 operations sequentially on the number. The operations are as follows: set(x, n, v) comp(x, n) get(x, n) sets the nth bit of the number r to v sets the value of the nth bit of r to its complement (1 if 0 and 0 otherwise) returns the value of the nth bit of the number r 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 r 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 opera- tions 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 r are cumulative, rather than each instruction operating independently on the original r Output format: Your output for comp and set each operation, each on a new line. For get commands, the output should be the requested bit’s value s will be the resulting value of the number r after Example Execution For example, a sample input file “filel.txt” contains the following (except the annotation comments) get o 0 comp 0 0 set 1 1 # get (x, 0), ignoring second value (0) # comp (x, 0), ignoring second value (0) # set (x, 1, The result of the sample run is $ ./first file1.txt Show transcribed image text 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 operations sequentially on the number. The operations are as follows: set(x, n, v) comp(x, n) get(x, n) sets the nth bit of the number r to v sets the value of the nth bit of r to its complement (1 if 0 and 0 otherwise) returns the value of the nth bit of the number r 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 r 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 opera- tions 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 r are cumulative, rather than each instruction operating independently on the original r Output format: Your output for comp and set each operation, each on a new line. For get commands, the output should be the requested bit’s value s will be the resulting value of the number r after Example Execution For example, a sample input file “filel.txt” contains the following (except the annotation comments) get o 0 comp 0 0 set 1 1 # get (x, 0), ignoring second value (0) # comp (x, 0), ignoring second value (0) # set (x, 1, The result of the sample run is $ ./first file1.txt

Leave a Reply

Your email address will not be published. Required fields are marked *