Question: c programming language well be creating a small program that...
C++ programming language
We’ll be creating a small program that will display all
binary in an int. We’ll be manipulating the bits
inside the integer and displaying them to the user.
First, however, we should set up some global (gasp!)
This function should take in a number to determine which
bit should be turned on (so a 3 would be bit 3,
starting from the right). Simply make sure that the
bit is turned on.
Just like TurnOn, only the opposite. So nothing like it.
This function will also take in a bit that it will
change, and then turn it off using a combination of
As in the previous two, this will take in a bit number and
toggle it using the OR bitwise operator.
Invert all the bits using the negate operator
Left and Right Shift-
These two separate functions will left and
right shift the number just once in the respective direction.
In the global space, declare an int that we will be
manipulating using our functions. Then, down in main,
make sure you display the bits of the integer,
so a bunch of 0’s. Under the right-most bit, display a
carrot, or something to mark which bit you’re looking at.
Something like this:
Allow the user to cycle through the bits using the left
right arrow keys. Once a bit has selected, allow
the functions to change the bits. F1 will turn it on,
F2 will toggle it, F3 will turn it off,
F4 will negate the entire int, and left and right shift
keys will, well, shift left and right.
Do not use std::bitset to display the bits. This will be a
That’s it! Once you can comfortably
destroy this poor number, consider displaying the actual
number to the screen so you can see how the bits affect the
whole decimal number.