Can someone tell me if my thought process is correct?

Viewed 67

So, I am working on a homework problem and I just want to know if I'm right in my thinking of what needs to be done.

Homework Problem:

Write C statements that sets (i.e., sets to 1) bits 0 and 1 of the variable “x” without disturbing the other bits using bit-level C operators. The variable mask declared below must be used, otherwise no points will be given. int mask = 0x00001800; int x = arbitrary_value;

So, my thought process is that I am being asked to set the bit in 0th position and the 1st position to 1 (at least that's how I have interpreted it). So, does that mean I need to right shift mask by 11 (?) and then would I do something like mask|x; that way, whatever the value of x, once it is ORed with the shifted mask, it will be 1 regardless? Am I on the right track? Am I close?

0 Answers
Related