

Study with the several resources on Docsity
Earn points by helping other students or get them with a premium plan
Prepare for your exams
Study with the several resources on Docsity
Earn points to download
Earn points by helping other students or get them with a premium plan
practice for bitwise opertations and other problems to help
Typology: Exercises
1 / 2
This page cannot be seen from the preview
Don't miss anything!


x >> 3 (logical) 0001 1010 ~x 0010 1100 x >> 3 (arithmetic) 1111 1010 !x 0000 0000 x << 4 0011 0000 x * 8 (this is essentially x << 3) 1001 1000
x * 64 => x << 6 x * 7 => (x << 3) – x OR (x << 2) + (x << 1) + x x * 23 => (x << 4) + (x << 3) - x
x = 1011 0110 y = 1010 0010 x & y 0xA x | y 0xB x ^ y 0x
// this function returns 1 is x < 0, otherwise it returns 1 // legal operations:! ~ & ^ | + << >> // max number of total operations allowed: 6 int isNegative(int x){ int y = x >> 31; return !!y // note that this is one of many solutions that could be possible for this problem! }
Create a mask with Shifting and Bitwise Ops char mask =? << ?; Use the mask to Set Bit 5 of value to a 0 value = value? mask; // Do not use XOR char mask = ~(1 << 5); value = value & mask;