Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Can anyone please help me figure out how to write this in C++? I've already written the helper functions and confirmed those are working/written properly

Can anyone please help me figure out how to write this in C++? I've already written the helper functions and confirmed those are working/written properly but I'm having a lot of trouble understanding what to do in Main() :( We really haven't gone over this in class beyond bitwise operators, and I'm lost. Thanks for any help.

Objective

Well be creating a small program that will display all the binary in an int. Well be manipulating the bits inside the integer and displaying them to the user. First, we should set up some global helper functions.

TurnOn

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 XOR 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.

If you are looping or using an array or vector in any of the above functions, you are doing it wrong.

Main.cpp

In the global space, declare an unsigned 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 0s. Under the right-most bit, display a caret or something to mark which bit youre looking at.

Also, display the actual number to the screen so you can see how the bits affect the whole decimal number.

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 severe grading hit.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Internals A Deep Dive Into How Distributed Data Systems Work

Authors: Alex Petrov

1st Edition

1492040347, 978-1492040347

More Books

Students also viewed these Databases questions

Question

Explain termination of employment.

Answered: 1 week ago

Question

=+ d. a professor deciding how much to prepare for class

Answered: 1 week ago

Question

=+ a. a family deciding whether to buy a new car

Answered: 1 week ago