// 56.
#define PRINT(int) printf("%d\n", int)
int x=2, y=1, z=0;
x = ((x && y) || z); PRINT(x); | (2&&1)||0) à x=1 |
PRINT(x ||!y && z); | ( || (() && ))à (1) |
// 57.
#define PRINT3(x, y, z) printf("x = %d\t y = %d\t z = %d\n", x, y, z)
int x, y, z;
x = y = z = 1;
++x || ++y && ++z | (x=2) à |
PRINT3(x, y, z) | x=2 y=1 z=1 |
x = y = z = 1;
++x && ++y || ++z | ((x=2) && ((y=2)) à à z |
PRINT3(x, y, z) | x=2 y=2 z=1 |
x = y = z = 1;
++x && ++y && ++z | (x=2) && ((y=2) && (z=2) |
PRINT3(x, y, z) | x=2 y=2 z=2 |
x = y = z = -1;
++x && ++y || ++z | (x=0) à à y , à z =0 à |
PRINT3(x, y, z) | x=0 y= -1 z=0 |
x = y = z = -1;
++x || ++y && ++z | (x=0) à ((y=0)à à z ) |
PRINT3(x, y, z) | x=0 y=0 z= -1 |
x = y = z = -1;
++x && ++y && ++z | (x=0) à à y z |
PRINT3(x, y, z) | x=0 y=-1 z=-1 |
// 58.
int main() //
{
Int x, y, z;
x = 03; y = 02; z = 01;
printf("%d\n", x | y & z); //3
printf("%d\n", x | y & ~z); //3
printf("%d\n", x ^ y & ~z); //1
printf("%d\n", x & y && z); //1
x = 1; y = -1;
printf("%d\n",!x | x); //1
printf("%d\n", ~x | x); //-1
printf("%d\n", x ^ x); //0
x <<= 3;
printf("%d\n", x); //8
y <<= 3;
printf("%d\n", y); //-8
y >>= 3;
printf("%d \n ", y); //-1
_getch();
return 0;
}
-----------------------------------------------------------------------------------------
// 59.
& 2, 4 ..:
unsigned ui, mask = 0x01; //( 2); 0x03 ( 4); 0x07 ( 8); 0x0f ( 16); 0x1f ( 32);
ui = 7;
ui & mask; //- , 2
00000111 - 7
00000001 - 2
------------
00000001 - 1 ( 7 & 2)
-----------------------------------------------------------------------------------------
// 60.
16- ( 0 15). , 0-4 , 5-11 2, 12 14 3. :
int , XX = 32151, x1, x2, x3; //X
|
|
// xxxx xxxx xxx x xxxx
//x1, x2, x3
.....
X = XX; // xxxx xxxx xxx x xxxx
x1 = X & 31; // 0 4: 31 = 0000 0000 0001 11112
X = X / 32; // 5 ,
// >>= 5: 0000 0 x xx x xxx xxxx
x2 = X & 127; // 7 , 5-11
//127 = $7F = 0000 0 0 00 0111 1111
X = X / 128; // 7
// >>= 7: 0000 0000 0000 x xxx
x3 = X & 7; // 3 , 12 14
//7 = $7 = 0000 000 0 0000 0 111
-----------------------------------------------------------------------------------------
// 61.
3- Button ( char) : , , 0 2. :
LeftButton = (Button & 1) == 1; //
RightButton = (Button & 2) == 2; //
LeftRightButton = (Button & 3) == 3; //
MiddleButton = (Button & 4) == 4; //
LeftMiddleButton = (Button & 5) == 5; //
-----------------------------------------------------------------------------------------
while
1 10
// 62.
, : summa (summa=0); .
// _1
const int N=10;
int main ()
{
int i = 1, summa = 0; //
// i
while (i <= N)
{ summa += i; //
i++; //
}
cout << summa<< endl;
_getch(); //
return 0;
}
// _2
const int N=10;
int main ()
{
int i = 1, summa = 0; //
//i ࠠ
while (i <= N)
summa += i++; //
cout << summa<< endl;
_getch(); // ,
return 0;
}