Question: Introduction In this homework, you will do bit operations on various built - in types ( int , char, short, etc. ) using templated classes

Introduction In this homework, you will do bit operations on various built-in types (int, char, short, etc.) using templated classes and iterators. There are two classes: 1) Bitter, which contains the built-in variable and is responsible for getting/setting/manipulating the bits of the variable content, and 2) BIT erator, which is a friend iterator class for the Bitter class which is used to traverse the bits from left to right (from Most Significant Bit (MSB) to Least Significant Bit (LSB)). Both classes are template classes. Also, you will overload the output stream operator for the Bitter class. In the Bitter class, the bits are counted starting from the right, so the LSB bit is indexed as 0, the one on its left is indexed as 1, etc... (Please see the main file which is attached with this homework bundle, and the sample outputs below to understand better what you will implement. Details can be hidden in the main file (e.g., object sharing). So, please read and analyze the main function and the corresponding outputs very carefully. You will see some int parameters which will be used to represent a bit (i.e.,0 or 1). You are not required to check the validity of these parameters. They will be either 0 or 1 in the tests we will do.- Do NOT use a library or any other helper class to perform bit operations and implement the functions needed to make the given main function compile, work, and generate the output given in the sample runs below. - You are required to use the bitwise operations we saw in the class e.g.,<<,>>, &,|, etc.. - The Bitter and BIT erator functions can be seen from the main function file. Note about implementation We are giving the main function in the main.cpp file with the homework bundle for you to use. Do not modify the main function. You are asked to use it and implement the other needed classes (Bitter and BIT erator) within the main.cpp file for the program to work correctly. Please make sure to understand the main function before you start implementing the other needed classes. Sample Runs Some sample runs are given below, but these are not comprehensive; therefore, you have to consider all possible cases to get full marks. Please do not try to understand the requirements by checking out the sample runs details only. They may give you just an idea, but you have to read the requirements from the document to understand fully what to do. Below are different values for the variable c in the first two lines of the main function in the main.cpp file, and the expected output. Case 1: typedef int C; C c =145960; Expected Output: bitter1 has value 00000000000000100011101000101000 bitter1 has 7 set bits inside bitter2 is created from the same object bitter2 has value 00000000000000100011101000101000 flipping the 0th and 3rd bits of bitter2 bitter1 has value 00000000000000100011101000100001 bitter2 has value 00000000000000100011101000100001 bitter2 has 7 set bits inside setting the 1st bit of bitter1 to 1 and 3rd bit of bitter2 to 0 bitter1 has value 00000000000000100011101000100011 bitter2 has value 00000000000000100011101000100011 setting the 11th bit of bitter1 to 1 set is done successfully bitter1 has value 00000000000000100011101000100011 negating the bits of bitter1 bitter1 has value 11111111111111011100010111011100 shifting bitter13 to the left and put 1 for the new bits bitter1 has value 11111111111011100010111011100111 shifting bitter23 to the right and put 0 for the new bits bitter2 has value 00011111111111011100010111011100 we are using an iterator to obtain the decimal value of bitter1 value for 00011111111111011100010111011100 is 536724956 value for 11100000000000100011101000100011 is 3758242339 Case 2: typedef char C; C c ='a'; Expected Output: bitter1 has value 01100001 bitter1 has 3 set bits inside bitter2 is created from the same object bitter2 has value 01100001 flipping the 0th and 3rd bits of bitter2 bitter1 has value 01101000 bitter2 has value 01101000 bitter2 has 3 set bits inside setting the 1st bit of bitter1 to 1 and 3rd bit of bitter2 to 0 bitter1 has value 01100010 bitter2 has value 01100010 setting the 11th bit of bitter1 to 1 you are out of index: 11>=8 negating the bits of bitter1 bitter1 has value 10011101 shifting bitter13 to the left and put 1 for the new bits bitter1 has value 11101111 shifting bitter23 to the right and put 0 for the new bits bitter2 has value 00011101 we are using an iterator to obtain the decimal value of bitter1 value for 00011101 is 29 value for 11100010 is 226 Case 3: typedef short C; C c =1000; Expected Output: bitter1 has value 0000001111101000 bitter1 has 6 set bits inside bitter2 is created from the same object bitter2 has value 0000001111101000 flipping the 0th and 3rd bits of bitter2 bitter1 has value 0000001111100001 bitter2 has value 0000001111100001 bitter2 has 6 set bits inside setting the 1st bit of bitter1 to 1 and 3rd bit of bitter2 to 0 bitter1 has value 0000001111100011 bitter2 has value 0000001111100011

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Programming Questions!