Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

/** Class: ense352 Description: Test code for as1 q1.cpp */ #include <stdint.h>

ID: 3870748 • Letter: #

Question

/**
Class: ense352
Description: Test code for as1 q1.cpp
*/

#include <stdint.h>
#include <iostream>
#include <cassert>

#include "q1.h" // students must write this file

////////////////////////////////////////////////////////////////
// test code

// FIXME: should rewrite so the type of x can be changed throughout to
// short int or simply int. Perhaps a template class

void test_0x89abcdef_0x76543210()
{
int res = shuffle_words(0x89abcdef, 0x76543210);
assert(res == 0x895432ef);
}
void test_0x00000000_0xfefefefe()
{
int res = shuffle_words(0x00000000, 0xfefefefe);
// the cast to signed is necessary to avoid a compiler warning about
// comparison between signed and unsigned integers.
assert(res == (signed)0x00fefe00);
}

int main()
{
std::cout << "for this machine, sizeof(int)=" << sizeof(int) << std::endl;
  
test_0x89abcdef_0x76543210();
test_0x00000000_0xfefefefe();
std::cout << "Ok ";
  
}

1. (5 marks) Implement a C function with the following prototype * Given words x and y, assumed to be at least 32-bits in size, return * a word composed of bytes 0 and 3 of x, and the remaining bytes taken * from y. * For operands exttt{x = Ox89ABCDEF} and exttt{y = 0x76543210, this would give exttt10x895432EF int shufflel_words(int x, int y);

Explanation / Answer

#include<stdio.h>

int func(int a, int b){

   int c;
   c = 0;

   a = a & 0xFF0000FF;

   b = b & 0x00FFFF00;

   c = b | a;
  
}

int main(){

int a, b;

a = 0x89ABCDEF;
b = 0x76543210;
printf("%x",func(a,b));
return 0;
}