# 我在哪里可以找到C的C换档指南?[英] Where can I find a bit shifting guide for C?

## 推荐答案

```(7 >> 1)
```

## 其他推荐答案

.

```// 1234 in hexadecimal. Do you understand this is not 1234 in decimal? Do you understand
// how specifying in hex makes it easier to think about the binary representation?
unsigned short i = 0x1234;
// Flip all the bits in 0x1234
printf("%04x", ~i);

// Test - Is the most significant bit set?
// mask is a binary number with the most significant bit set. Do
// you understand why this is so?
{
printf("bit set!");
}
else
{
printf("bit cleared!");
}

// Set the most significant bit
printf("Set the MSB of i, check it out: %i\n", i)

// Set the second most significant bit
// Do you see how by shifting mask right one it becomes the next most significant bit?
i = i | (mask >> 1);
```

## 其他推荐答案

```x = y << 3;
```

```x = z >> 2
```

i 0bcd efgh

.

.

```0001001000110100  write out the bits
x0001001000110100 shift right one
0000100100011010  because this is a rotate fill in the new bit with the bit that fell off on the prior operation
```

```0000100100011010
xx0000100100011010
1000001001000110
```

```unsigned int rotate_right_one ( unsigned int x )
{
unsigned int y;
y = x & 1;  // Save the bit that is about to fall off the right
x >> = 1;  // Logical rotate one bit
x |= y<<31; // This assumes that unsigned int is 32 bits.
return(x);
}
```

```abcd
bcda  first rotate
cdab  second
dabc  third
abcd  fourth
bcda  fifth
```

```abcd
bcda  one bit left.
```

.

```for(count=0, r=1; r; r<<=1)
if(r&some_variable)
count++;
```