1. Engineering
  2. Computer Science
  3. c programming language well be creating a small program that...

Question: c programming language well be creating a small program that...

Question details

C++ programming language

We’ll be creating a small program that will display all the
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!)
helper functions.

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.

TurnOff –
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
bitwise operators.

Toggle –
As in the previous two, this will take in a bit number and
toggle it using the OR bitwise operator.

Negate –
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.

Main.cpp –
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:

Bits: 0000000000000000

Allow the user to cycle through the bits using the left and
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.

Solution by an expert tutor
Blurred Solution
This question has been solved
Subscribe to see this solution