C
Ceriousmall
Guys I wanna say thanks for all the help and pointers with this
bitwise exercise.
This is the code I've come up with.......
unsigned setbits(unsigned x, int p, int n, unsigned y)
{
unsigned mask = ~(~0 << n);
return x & ~(mask << (p+1-n)) | ((y & mask) << (p+1-n));
}
bitwise exercise.
This is the code I've come up with.......
unsigned setbits(unsigned x, int p, int n, unsigned y)
{
unsigned mask = ~(~0 << n);
return x & ~(mask << (p+1-n)) | ((y & mask) << (p+1-n));
}