CC
(V
isu
al
C+
+
6.
0
8
(1)
(2)
(3)
(4)
8
(V
isu
al
C+
+
6.
0
8.1 C
8.2
8.3
8.4
(V
isu
al
C+
+
6.
0
8.1 C
8.1
8.1
(V
isu
al
C+
+
6.
0
8.1l8_1.cpp
#include "stdio.h"
main()
{ int a,b;
printf("input the numbers,");
scanf("%d,%d",&a,&b);
printf("%d\n",a&b); /**/
printf("%d\n",a|b); /**/
printf("%d\n",a^b); /**/
printf("%u\n",~a); /* a*/
}
input the numbers,9,5 < CR >
1
13
12
65526
[8.1]
(V
isu
al
C+
+
6.
0
8.2
8.2.1
8.2.2
C
(V
isu
al
C+
+
6.
0
8.2.1
&
|
^
~
<<
>>
8-1
8-1
(V
isu
al
C+
+
6.
0
8.2.1
1 &
2 |
3 ^
4 ()
5 (<<)
6 (>>)
(V
isu
al
C+
+
6.
0
1 &)
1
1100&0=00&1=01&0=01&1=1
9&5
9 0 0 0 0 1 0 0 1
5 0 0 0 0 0 1 0 1
& ___________________
0 0 0 0 0 0 0 1(1)
9&5=1
(V
isu
al
C+
+
6.
0
1 &)
2
010001 8.2
&18.3
&18.4
8.2
(V
isu
al
C+
+
6.
0
8.2001101101
0 0 1 1 0 1 1 0
1 1 0 0 0 0 0 0 0100000000000000
& ___________________
0 0 0 0 0 0 0 0
#include "stdio.h"
main()
{ int a=0x36,b=0xc0,c;
c=a&b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
a=36
b=c0
c=0
[8.2]
8.3
(V
isu
al
C+
+
6.
0
8.3a0
a&255(2550000000011111111)
#include "stdio.h"
main()
{ int a,b=255,c;
scanf("%d",&a);
c=a&b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
920< CR >
a=398
b=ff
c=98
[8.3]
8.4
(V
isu
al
C+
+
6.
0
8.4a=9l8_4cpp
#include "stdio.h"
main()
{ int a=9,b=1,c;
c=a&b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
a=9
b=1
c=1
[8.4]
(V
isu
al
C+
+
6.
0
2 |
1
110|0=00|1=11|0=11|1=1
9|50 0 0 0 1 0 0 1
0 0 0 0 0 1 0 1
| _________________
0 0 0 0 1 1 0 1 (13)
9|5=13
2
1
18.5
8.5
(V
isu
al
C+
+
6.
0
8.551l8_5.cpp
00011111”&
# # # # # # # # (#01)
0 0 0 1 1 1 1 1
| _______________
# # # 1 1 1 1 1
#include "stdio.h"
main()
{ int a,b=31,c;
scanf("%d",&a);
c=a|b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
5< CR >
a=5
b=1f
c=1f
[8.5]
(V
isu
al
C+
+
6.
0
3 ^
1
10^0=00^1=11^0=11^1=0
9^50 0 0 0 1 0 0 1
0 0 0 0 0 1 0 1
^_____________
0 0 0 0 1 1 0 0 (12) 9^5=12
2
8.6
1
0
8.7
8.6
(V
isu
al
C+
+
6.
0
8.6011100014 4
0 1 1 1 0 0 0 1
0 0 0 0 1 1 1 1
^ ______________
0 1 1 1 1 1 1 0 (126)
#include "stdio.h"
main()
{ int a=0x71,b=0xf,c;
c=a^b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
a=71
b=f
c=7e
[8.6]
8.7
(V
isu
al
C+
+
6.
0
8.7 a=5b=7ab
a=a^b;b=b^a;a=a^b;ab
a 0000000000000101
b 0000000000000111
a=a^b 0000000000000010
a 0000000000000010
b 0000000000000111
b=b^a 0000000000000101 (b5)
a 0000000000000010
b 0000000000000101
a=a^b 0000000000000111 a7
8.7
(V
isu
al
C+
+
6.
0
l8_7.cpp
#include "stdio.h"
main()
{ int a=5,b=7;
printf("a=%d,b=%d\n",a,b);
a=a^b;b=b^a;a=a^b;
printf("a=%d,b=%d\n",a,b);
}
a=5,b=7
a=7,b=5
[8.7]
(V
isu
al
C+
+
6.
0
4 (~)
1
~0=1~1=0
9
0000000000001001
~ __________________
1111111111110110
2
a0a=a&~1;a1632
(V
isu
al
C+
+
6.
0
5 (<<)
1
<<” <<”0
a<<4a4a=00000011(3)400110000(48)
2
12n2n 1
C2
(V
isu
al
C+
+
6.
0
6 (>>)
1
>>” >>”
2
12n2n
3
01010 1 1
a,1001011111101101
a>>1,0100101111110110 ( )
a>>1,1100101111110110 ( )
(V
isu
al
C+
+
6.
0
8.2.2
1
8-2
2
1
2a&=2;a=a&2;
(V
isu
al
C+
+
6.
0
8-2
&= a&=b a=a&b
|= a|=b a=a|b
^= a^=b a=a^b
>>= a>>=b a=a>>b
<<= a<<=b a=a<<b
(V
isu
al
C+
+
6.
0
8.3
1
2
38.8
——
(V
isu
al
C+
+
6.
0
1
1
2
(V
isu
al
C+
+
6.
0
(1)
struct <>
{ <>
};
struct <> <>;
struct <>
{ <>
}<>;
struct
{ <>
}<>;
<> <><>;
(V
isu
al
C+
+
6.
0
(1)
struct bs
{ unsigned a:8;
unsigned b:2;
unsigned c:6;
}data;
datastruct bsa8b2c68-1
8 2 6 (
8-1data
a b c
(V
isu
al
C+
+
6.
0
2
<>.<>
data.a=2;dataa2
(V
isu
al
C+
+
6.
0
2
1
2
323
4
5
6
8.8
(V
isu
al
C+
+
6.
0
8.8l8_8.cpp
#include "stdio.h"
main()
{ struct bs
{ unsigned a:1;
unsigned b:3;
unsigned c:4;
} bit,*pbit;
bit.a=1; /**/
bit.b=7;
bit.c=15;
printf("%d,%d,%d\n",bit.a,bit.b,bit.c);/**/
pbit=&bit; /*bitpbit*/
pbit->a=0; /*a0*/
8.8
(V
isu
al
C+
+
6.
0
pbit->b&=3;
pbit->c|=1;
printf("%d,%d,%d\n",pbit->a,pbit->b,pbit->c);
/**/
}
1715
0315
[8.8]
(V
isu
al
C+
+
6.
0
8.4
[8.9]
[8.10]
8.9
(V
isu
al
C+
+
6.
0
8.9 a58l8_9.cpp
1a58-4
24(8-5+1)101440
34
15 9 8 5 4 3 0
15 9 8 5 4 3 0
mn a>>5” a>>m” ~(~0<<3)” ~(~0<<(m-n+1))”
8.9
(V
isu
al
C+
+
6.
0
#include "stdio.h"
main()
{ unsigned a,b,c,d;
printf("input a number:");
scanf("%d",&a);
b=a>>5;
c=~(~0<<4);
d=b&c;
printf("a=%x\td=%x\n",a,d);
}
input a number,421 < CR >
a=01a5 d=d
[8.9]
8.10
(V
isu
al
C+
+
6.
0
8.10xnl8_10.cpp
216-nn8-5 xab
a16-nn0
bn16-n0
n 16-n
16-n n
8.10
(V
isu
al
C+
+
6.
0
#include "stdio.h"
main()
{ unsigned x,a,b,c;
int n;
scanf("%d,%d",&x,&n);
a=x>>(16-n);
b=x<<n;
c=a|b;
printf("x=%x,c=%x",x,c);
}
400,3 < CR >
x=190,c=c80
[8.10]
(V
isu
al
C+
+
6.
0
8
(1)
(2)
(3)
(4)
8
(V
isu
al
C+
+
6.
0
8.1 C
8.2
8.3
8.4
(V
isu
al
C+
+
6.
0
8.1 C
8.1
8.1
(V
isu
al
C+
+
6.
0
8.1l8_1.cpp
#include "stdio.h"
main()
{ int a,b;
printf("input the numbers,");
scanf("%d,%d",&a,&b);
printf("%d\n",a&b); /**/
printf("%d\n",a|b); /**/
printf("%d\n",a^b); /**/
printf("%u\n",~a); /* a*/
}
input the numbers,9,5 < CR >
1
13
12
65526
[8.1]
(V
isu
al
C+
+
6.
0
8.2
8.2.1
8.2.2
C
(V
isu
al
C+
+
6.
0
8.2.1
&
|
^
~
<<
>>
8-1
8-1
(V
isu
al
C+
+
6.
0
8.2.1
1 &
2 |
3 ^
4 ()
5 (<<)
6 (>>)
(V
isu
al
C+
+
6.
0
1 &)
1
1100&0=00&1=01&0=01&1=1
9&5
9 0 0 0 0 1 0 0 1
5 0 0 0 0 0 1 0 1
& ___________________
0 0 0 0 0 0 0 1(1)
9&5=1
(V
isu
al
C+
+
6.
0
1 &)
2
010001 8.2
&18.3
&18.4
8.2
(V
isu
al
C+
+
6.
0
8.2001101101
0 0 1 1 0 1 1 0
1 1 0 0 0 0 0 0 0100000000000000
& ___________________
0 0 0 0 0 0 0 0
#include "stdio.h"
main()
{ int a=0x36,b=0xc0,c;
c=a&b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
a=36
b=c0
c=0
[8.2]
8.3
(V
isu
al
C+
+
6.
0
8.3a0
a&255(2550000000011111111)
#include "stdio.h"
main()
{ int a,b=255,c;
scanf("%d",&a);
c=a&b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
920< CR >
a=398
b=ff
c=98
[8.3]
8.4
(V
isu
al
C+
+
6.
0
8.4a=9l8_4cpp
#include "stdio.h"
main()
{ int a=9,b=1,c;
c=a&b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
a=9
b=1
c=1
[8.4]
(V
isu
al
C+
+
6.
0
2 |
1
110|0=00|1=11|0=11|1=1
9|50 0 0 0 1 0 0 1
0 0 0 0 0 1 0 1
| _________________
0 0 0 0 1 1 0 1 (13)
9|5=13
2
1
18.5
8.5
(V
isu
al
C+
+
6.
0
8.551l8_5.cpp
00011111”&
# # # # # # # # (#01)
0 0 0 1 1 1 1 1
| _______________
# # # 1 1 1 1 1
#include "stdio.h"
main()
{ int a,b=31,c;
scanf("%d",&a);
c=a|b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
5< CR >
a=5
b=1f
c=1f
[8.5]
(V
isu
al
C+
+
6.
0
3 ^
1
10^0=00^1=11^0=11^1=0
9^50 0 0 0 1 0 0 1
0 0 0 0 0 1 0 1
^_____________
0 0 0 0 1 1 0 0 (12) 9^5=12
2
8.6
1
0
8.7
8.6
(V
isu
al
C+
+
6.
0
8.6011100014 4
0 1 1 1 0 0 0 1
0 0 0 0 1 1 1 1
^ ______________
0 1 1 1 1 1 1 0 (126)
#include "stdio.h"
main()
{ int a=0x71,b=0xf,c;
c=a^b;
printf("a=%x\nb=%x\nc=%x\n",a,b,c);
}
a=71
b=f
c=7e
[8.6]
8.7
(V
isu
al
C+
+
6.
0
8.7 a=5b=7ab
a=a^b;b=b^a;a=a^b;ab
a 0000000000000101
b 0000000000000111
a=a^b 0000000000000010
a 0000000000000010
b 0000000000000111
b=b^a 0000000000000101 (b5)
a 0000000000000010
b 0000000000000101
a=a^b 0000000000000111 a7
8.7
(V
isu
al
C+
+
6.
0
l8_7.cpp
#include "stdio.h"
main()
{ int a=5,b=7;
printf("a=%d,b=%d\n",a,b);
a=a^b;b=b^a;a=a^b;
printf("a=%d,b=%d\n",a,b);
}
a=5,b=7
a=7,b=5
[8.7]
(V
isu
al
C+
+
6.
0
4 (~)
1
~0=1~1=0
9
0000000000001001
~ __________________
1111111111110110
2
a0a=a&~1;a1632
(V
isu
al
C+
+
6.
0
5 (<<)
1
<<” <<”0
a<<4a4a=00000011(3)400110000(48)
2
12n2n 1
C2
(V
isu
al
C+
+
6.
0
6 (>>)
1
>>” >>”
2
12n2n
3
01010 1 1
a,1001011111101101
a>>1,0100101111110110 ( )
a>>1,1100101111110110 ( )
(V
isu
al
C+
+
6.
0
8.2.2
1
8-2
2
1
2a&=2;a=a&2;
(V
isu
al
C+
+
6.
0
8-2
&= a&=b a=a&b
|= a|=b a=a|b
^= a^=b a=a^b
>>= a>>=b a=a>>b
<<= a<<=b a=a<<b
(V
isu
al
C+
+
6.
0
8.3
1
2
38.8
——
(V
isu
al
C+
+
6.
0
1
1
2
(V
isu
al
C+
+
6.
0
(1)
struct <>
{ <>
};
struct <> <>;
struct <>
{ <>
}<>;
struct
{ <>
}<>;
<> <><>;
(V
isu
al
C+
+
6.
0
(1)
struct bs
{ unsigned a:8;
unsigned b:2;
unsigned c:6;
}data;
datastruct bsa8b2c68-1
8 2 6 (
8-1data
a b c
(V
isu
al
C+
+
6.
0
2
<>.<>
data.a=2;dataa2
(V
isu
al
C+
+
6.
0
2
1
2
323
4
5
6
8.8
(V
isu
al
C+
+
6.
0
8.8l8_8.cpp
#include "stdio.h"
main()
{ struct bs
{ unsigned a:1;
unsigned b:3;
unsigned c:4;
} bit,*pbit;
bit.a=1; /**/
bit.b=7;
bit.c=15;
printf("%d,%d,%d\n",bit.a,bit.b,bit.c);/**/
pbit=&bit; /*bitpbit*/
pbit->a=0; /*a0*/
8.8
(V
isu
al
C+
+
6.
0
pbit->b&=3;
pbit->c|=1;
printf("%d,%d,%d\n",pbit->a,pbit->b,pbit->c);
/**/
}
1715
0315
[8.8]
(V
isu
al
C+
+
6.
0
8.4
[8.9]
[8.10]
8.9
(V
isu
al
C+
+
6.
0
8.9 a58l8_9.cpp
1a58-4
24(8-5+1)101440
34
15 9 8 5 4 3 0
15 9 8 5 4 3 0
mn a>>5” a>>m” ~(~0<<3)” ~(~0<<(m-n+1))”
8.9
(V
isu
al
C+
+
6.
0
#include "stdio.h"
main()
{ unsigned a,b,c,d;
printf("input a number:");
scanf("%d",&a);
b=a>>5;
c=~(~0<<4);
d=b&c;
printf("a=%x\td=%x\n",a,d);
}
input a number,421 < CR >
a=01a5 d=d
[8.9]
8.10
(V
isu
al
C+
+
6.
0
8.10xnl8_10.cpp
216-nn8-5 xab
a16-nn0
bn16-n0
n 16-n
16-n n
8.10
(V
isu
al
C+
+
6.
0
#include "stdio.h"
main()
{ unsigned x,a,b,c;
int n;
scanf("%d,%d",&x,&n);
a=x>>(16-n);
b=x<<n;
c=a|b;
printf("x=%x,c=%x",x,c);
}
400,3 < CR >
x=190,c=c80
[8.10]