subject

Define a class named Bits that holds a single integer variable. You will use this integer simply as a container of bits. The number of bits you can support depends on the type of integer you use. We will use an unsigned long long, which on most platforms occupies 64 bits. However, DO NOT HARD-CODE the type of integer you use throughout your code. You should be able to change only one line of code for your class to work with a different size integer (see the using statement on the second code line below). The code skeleton below gets you started, and also shows you the interface your class needs to implement. I gave you the code for some of the functions. The body of at should help you with many other functions. class Bits { using IType = unsigned long long; // We only have to change the integer type here, if desired enum {NBITS = sizeof (IType) *8}; IType bits = 0; public: Bits () = default; Bits (IType n) { bits = n; } static int size () { return NBITS; bool at(int pos) const { // Returns (tests) the bit at bit-position pos assert (0 <= pos && pos < NBITS); return bits & (IType (1) << pos); } void set (int pos); // Sets the bit at position pos void set(); // Sets all bits void reset (int pos); // Resets (makes zero) the bit at position pos void reset(); // Resets all bits void assign(int pos, bool val); // Sets or resets the bit at position pos depending on val vois assign (IType n); // Replaces the underlying integer with n void toggle(int pos); // Flips the bit at position pos void toggle(); // Flips all bits void shift (int n) ; // If n > 0, shifts bits right n places; if n <0, shifts left void rotate (int n); // If n > 0, rotates right n places; if n < 0, rotates left int ones () const; // Returns how many bits are set in the underlying integer int zeroes () const { // Returns how many bits are reset in the underlying integer return NBITS ones(); ) IType to_int() const { return bits; 1 friend bool operator==(const Bits & bl, const Bits & b2) { return bl. bits b2.bits; 1 friend bool operator!=(const Bits& bl, const Bits & b2) { return bl. bits != b2.bits; 1 friend std::ostream& operator<<(std::ostream& os, const Bits & b) { return os << std::bitset (b. bits); // Be sure to #include ) ==
I have also defined for you the following non-member, friend functions:
an output stream operator (<<) that prints the bits to an output stream (without a newline; hint: use std::bitset)
the equality operator ==
the inequality operator !=
Remember that bit positions are numbered right-to-left, so bit-position 0 is the low-order (right-most) bit. "Rotate" means that bits that fall off one end replace the vacated bits on the other (in the same order as they appeared originally).
Define all functions inline in a header file named bits. h.
rotate is the most interesting function to implement.
I suggest that you develop your code offline in the development environment of your own choice, implementing and testing one function at a time. When you are satisfied everything is working, submit your code for grading.
Something think about
What will you do if a user of your Bits class tries to use a bit position out of range of what the integer holds? You can just use asserts for now, as shown above.
Remember
Never use using namespace std; in a header file!

ansver
Answers: 1

Another question on Computers and Technology

question
Computers and Technology, 22.06.2019 16:30
Technician a says that a dry sump system uses no oil storage sump under the engine. technician b says that a wet sump system uses no oil storage sump under the engine. who is correct?
Answers: 3
question
Computers and Technology, 23.06.2019 03:10
Acomputer has a two-level cache. suppose that 60% of the memory references hit on the first level cache, 35% hit on the second level, and 5% miss. the access times are 5 nsec, 15 nsec, and 60 nsec, respectively, where the times for the level 2 cache and memory start counting at the moment it is known that they are needed (e.g., a level 2 cache access does not even start until the level 1 cache miss occurs). what is the average access time?
Answers: 1
question
Computers and Technology, 23.06.2019 09:10
Effective character encoding requires standardized code. compatible browsers. common languages. identical operating systems.
Answers: 1
question
Computers and Technology, 23.06.2019 13:30
Jace needs to answer a question on square roots to win a quiz. how can he use a spreadsheet to find the square root of 786? a. use the functions round and count b. create a table and chart c. use the function sqrt d. use the function now
Answers: 3
You know the right answer?
Define a class named Bits that holds a single integer variable. You will use this integer simply as...
Questions
question
Mathematics, 29.09.2021 22:00
question
Mathematics, 29.09.2021 22:00
question
Mathematics, 29.09.2021 22:00
question
Mathematics, 29.09.2021 22:00
question
Mathematics, 29.09.2021 22:00
Questions on the website: 13722367