/** 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 ";
}
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;
}
Related Questions
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.