Get premium membership and access questions with answers, video lessons as well as revision papers.

Create an overload rotate() function using C++ new style that left-rotates the bits in its argument and returns the result.Overload it so it accepts ints...

      

Create an overload rotate() function using C++ new style that left-rotates the bits in its argument and returns the result.Overload it so it accepts ints and longs.(A rotate is similar to a shift except that the bit shifted off one end is shifted onto the other end)

  

Answers


Davis
#include
using namespace std;
int rotate (int i);
long rotate (long i);
int main ()
{
int a;
long b;
a = 0x8000;
b = 8;
cout << rotate (a);
cout << "\n";
cout << rotate (b);
return 0;
}
int rotate (int i)
{
int x;
if (i & 0x8000) x = 1;
else x = 0;
i = i << 1;
i += x;
return i;
}
long rotate(long i)
{
int x;
if ( i & 0x80000000) x = 1;
else x = 0;
i = i << 1;
i += x;
return i;
}
Githiari answered the question on May 5, 2018 at 17:43


Next: Create a class in C++ language that holds name and address information.Store all the information in character strings that are private members of the class.Include...
Previous: Create a C++ class called stopwatch that emulates a stopwatch that keeps track of elapse time. Use a constructor to initially set the elapse time...

View More Computer Science Questions and Answers | Return to Questions Index


Learn High School English on YouTube

Related Questions