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

Other questions on the subject: Computers and Technology

image
Computers and Technology, 23.06.2019 13:30, powellmj9216
Spoons are designed to be used for: spring hammering. applying body filler. identifying high and low spots. sanding highly formed areas.
Answers: 3
image
Computers and Technology, 24.06.2019 02:10, ttangelique
Which sentences describe the things you need to ensure while creating a sketch and a drawing? while an artistic or creative drawing is a creative expression, a technical drawing is an informative expression. you need to create accurate and neat drawings to convey accurate information. a technical drawing clearly conveys its meaning or information, and does not leave room for interpretation maintain a good speed while creating drawings
Answers: 1
image
Computers and Technology, 25.06.2019 01:30, jamesvazquez3135
The physical parts or components of a computer system is called .
Answers: 1
image
Computers and Technology, 25.06.2019 07:50, munekalove69ounxwv
The “tab” key can a. create extra cells in a word table *b. move from cell to cell in a word table c. move from the top of a column to the bottom of a column in a word table d. none of the above a. none of these answers are correct b. move from cell to cell in a word table c. move from the top of a column to the bottom of a column in a word table d. create extra cells in a word table
Answers: 2
You know the right answer?
Define a class named Bits that holds a single integer variable. You will use this integer simply as...

Questions in other subjects:

Konu
Arts, 15.12.2021 22:40
Konu
Mathematics, 15.12.2021 22:40