. 10.
C- .
So
x = y << 3;
, - , , , "-"
x = z >> 2
.
K & R - , , C .
, , , ,
, 0xD, 1 , 0xE, lsbit 1101 , 1 1 1110
. , , 0xD 0 1101, 1 0110 a 0x6.
0 1011, 0xB .
- , ? , , 8- , , - bcde fghi, a - , - ,
e abcd fghi,
i abcd efgh, , 8- 4- .
( , - 0 + 0 - , , )
i 0bcd efgh, , , 32- 64- .
, , abcd bcd0 shift abcd right two 00ab.
: , , , , , 2 , . 0x0D, , 0b00001101 < 2 = 0b00110100 0x34 0xD 13 0x34 52 . 52 13. 2 2. - , . , 0x34 2, 0xD, , , 4 0xFC, . C 0xFC → 1 0x7E, 0x7E +126 ,
-4/2 = 126? , . , , , , , , 0bQWER, , 0bQQwe, , . 0bQQQW .. , lsbit, 0bQWER , 0bWER0. -4 , 0xF8, -8, -4 -8, . , , , , asl, , lsl ( ), , . , , asl asr lsr, lsl.
-, , . 0x1234 , ?
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
C?
unsigned int rotate_right_one ( unsigned int x )
{
unsigned int y;
y = x & 1;
x >> = 1;
x |= y<<31;
return(x);
}
, .
, rotate, , . , 5 , ?
abcd
bcda first rotate
cdab second
dabc third
abcd fourth
bcda fifth
?
abcd
bcda one bit left.
5-4 = 1. asl, , , nbits-shift .
, , , , .
, :
for(count=0,r=1;r;r<<=1) if(r&some_variable) count++;
, C .