Trusted by millions of Kenyans
Study resources on Kenyaplex

Get ready-made curriculum aligned revision materials

Exam papers, notes, holiday assignments and topical questions – all aligned to the Kenyan curriculum.

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

Answer Attachments

Exams With Marking Schemes

Related Questions