Question: int prob 2 5 9 ( int x , int y ) { return ( y & ~ 0 xFF ) | ( x &

int prob259(int x, int y){
return (y & ~0xFF)|(x & 0xFF);
}
unsigned replace_byte(unsigned x, int i, unsigned char b){
unsigned mask =0xFF <<(i *8);
return (x & ~mask)|(b <<(i *8));
}
int prob261A(int x){
return (x & 0xFF)==0xFF;
}
int prob261B(int x){
return (x & 0xFF000000)==0;
}
int prob261C(int x){
return (x & 0x00FFFFFF)==0x00FFFFFF;
}
int leftmost_one(unsigned x){
x |= x >>1;
x |= x >>2;
x |= x >>4;
x |= x >>8;
x |= x >>16;
return x & ~(x >>1);
}
int lower_one_mask(int n){
int mask =(1<<(n -1))-1;
return mask |(mask +1);
}
int main(){
// problem 2.59
printf("
Problem 2.59:
");
int x =0x89ABCDEF;
int y =0x76543210;
printf("0x%X
", prob259(x, y));
// problem 2.60
printf("
Problem 2.60:
");
printf("0x%X
", replace_byte(0x12345678,2,0xAB));
printf("0x%X
", replace_byte(0x12345678,0,0xAB));
// problem 2.61
printf("
Problem 2.61:
");
printf("%d
", prob261A(0x8)); // returns 1
printf("%d
", prob261B(-1)); // returns 0
printf("%d
", prob261C(0x100)); // returns 0
// problem 2.66

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!