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

Use a C++ union class to swap the low- and high-order bytes of an integer (assuming 16-bit integer; if the computer uses 32-bit integers, swap...

      

Use a C++ union class to swap the low- and high-order bytes of an integer (assuming 16-bit integer; if the computer uses 32-bit integers, swap the bytes of a short int)

  

Answers


Davis
#include
using namespace std;
union swapbytes {
unsigned char c [2];
unsigned i;
swapbytes (unsigned x);
void swp ();
};
swapbytes ::swapbytes (unsigned x)
i = x;
}
int main()
{
swapbytes on(1);
ob.swp ();
cout << on.i;
return 0;
}
Githiari answered the question on May 12, 2018 at 16:25


Next: Given the following base C++ class, class area_cl { public: double height; double width; }; Create two derived classes called rectangle and isosceles that inherit area_cl. Have each class include a...
Previous: Explain what an anonymous union is and how it differs from a normal union.

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


Learn High School English on YouTube

Related Questions