Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C++ please! Extra Credit: Implement the following problem. See the 2425 Grading and Submission Guide Sheets for additional grading/submission information. Partial credit will be

In C++ please!

image text in transcribed
Extra Credit: Implement the following problem. See the 2425 Grading and Submission Guide Sheets for additional grading/submission information. Partial credit will be given. (10 points) Bit masking is the act of applying a mask over a value to keep, change, or modify a piece of given information. A mask determines which bits to take, which bits to clear, and which bits to invert in a binary number. In general, there are three common bitwise operators that when applied to a given operand, with a programmer defined mask, can be used to set certain bits to a 0, a 1, or to the inverse of the given bit. Those operators are the bitwise and (&), the bitwise or (|), and the bitwise exclusive or (^). The table below shows how each of the three operators work: Bits Results Bit 1 Bit 2 Bit 1 6 Bit 2 Bit 1 | Bit 2 Bit 1 ^ Bit 2 0 0 0 0 0 1 0 0 0 1 0 Assume an n-bit word, with the rightmost bit in the internal representation (the least significant bit) is numbered 0, and the leftmost bit in the internal representation (the most significant bit) is numbered n- 1. For example, one can set bits 0, 2, 4, and 5 of an arbitrary operand, opnd, to a 1, leaving all other bits unchanged with the bitmask expression: opnd | 35, where the subscript x denotes a base 16 number. In this case the bitwise operator used is the bitwise or ( | ) and the mask chosen is 35x. Suppose opnd is an 8-bit word and opnd - abcd efgh, where the letters a-h are either a 0 or a 1. Then the hexadecimal 35 would be represented as 0011 0101. Thus: abcd efgh 0011 0101 abll elgl abll elgl Bit #s 7654 3210 Notice, after the bitwise operator and mask are applied to the original opnd, bits 0, 2, 4, and 5 result in a 1, but all other bits are unchanged. Write a program, given instructions for which bits need to be set to a zero, to a one, or to the inverse of the original bit, outputs the expression needed to accomplish the given task. Input will be from a data file. The first line will contain a single integer n that indicates the number of data sets that follow in the range [1, 20]. Each data set will consist of five lines. Line 1 indicates the number of bits in the operand opnd and will be guaranteed to be either 8, 16, or 32. Line 2 indicates the bits that are to be set to a 1, Line 3 indicates the bits that are to be set to a 0, Line 4 indicates the bits that are to be inverted, and Line 5 is 20 dashes whose purpose is to give a visual separation between the different data sets. Lines 2-4 will be comma separated lists. Lists will be in

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Introduction to Wireless and Mobile Systems

Authors: Dharma P. Agrawal, Qing An Zeng

4th edition

1305087135, 978-1305087132, 9781305259621, 1305259629, 9781305537910 , 978-130508713

More Books

Students also viewed these Programming questions

Question

Explain the phyla in kingdom fungi?

Answered: 1 week ago

Question

Explain the conditions necessary for the growth of fungi?

Answered: 1 week ago

Question

Plato concept of justice ?

Answered: 1 week ago

Question

Plato Theory of Education?

Answered: 1 week ago