Firstly, let me just state for the record that this is in prep for a midterm I have Wednesday.
I’m taking a C Programming course and we’ve barely even touched Bitwise Operations, but we’re being tested on them.
For instance, we’re supposed to know something like what A, B, C, and D are initialized as in code like this:
unsigned int A, B, C, D;
A = 0xfedc & 0x300c;
B = 0xba98 | 0x1236;
C = 0x7654 ^ 0xfa00;
D = ~0xffff3210;
If possible, could you provide me with a decent tutorial/guide for understanding these concepts? An explanation would be awesome too, but I’d prefer not to be handed an actual answer explanation.
Thanks in advance for any help you can spare me.
The first issue is:
&as bitwise AND,|as bitwise OR,^as bitwise XOR, and~as bitwise NOT?If not, you’ve got a problem or two and need to get to the point of recognizing them all.
Then you need to know what each operation means…
1, thenb1 & b2will be1; otherwise, it will be0.0, thenb1 | b2will be0; otherwise, it will be1.0or both1), thenb1 ^ b2will be0; otherwise it will be1.0,~b1will be1; otherwise, it will be0.You also need to recognize that the hex representation is closely related to the bit patterns in the number.
Combining these, you can deduce the answers for the questions shown, applying the bitwise operators to each bit of the operands.