1: namespace ConsoleApplication12
2: {
3: using System;
4:
5: public class Class1
6: {
7: public static bool returnTrue( int value )
8: {
9: return true;
10: }
11: public static bool returnFalse( int value )
12: {
13: return false;
14: }
15: public static int Main(string[] args)
16: {
17: Console.WriteLine("★★ 基本演算(みんな理解しよう)");
18: Console.WriteLine("2+3\t=\t{0}",2+3);
19: int x1=2147483647, y1=1;
20: Console.WriteLine("2147483647+1\t=\t{0}",x1+y1);
21: Console.WriteLine("2147483647u+1u\t=\t{0}",2147483647u+1u);
22: uint x2=4294967295u, y2=1u;
23: Console.WriteLine("4294967295u+1u\t=\t{0}",x2+y2);
24:
25: Console.WriteLine("3-2\t=\t{0}",3-2);
26: int x3=-2147483648, y3=1;
27: Console.WriteLine("-2147483648-1\t=\t{0}",x3-y3);
28: uint x4=0u, y4=1u;
29: Console.WriteLine("0u-1u\t=\t{0}",x4-y4);
30:
31: Console.WriteLine("3*2\t=\t{0}",3*2);
32: int x5=2147483647, y5=2;
33: Console.WriteLine("2147483647*2\t=\t{0}",x5*y5);
34: Console.WriteLine("2147483647u*2u\t=\t{0}",2147483647u*2u);
35:
36: Console.WriteLine("6/3\t=\t{0}",6/3);
37: Console.WriteLine("6/5\t=\t{0}",6/5);
38: Console.WriteLine("6.0/5.0\t=\t{0}",6.0/5.0);
39:
40: Console.WriteLine("6%3\t=\t{0}",6%3);
41: Console.WriteLine("6%5\t=\t{0}",6%5);
42:
43: Console.WriteLine("1<2\t=\t{0}",1<2);
44: Console.WriteLine("2<1\t=\t{0}",2<1);
45: Console.WriteLine("3<3\t=\t{0}",3<3);
46: Console.WriteLine("1>2\t=\t{0}",1>2);
47: Console.WriteLine("2>1\t=\t{0}",2>1);
48: Console.WriteLine("3>3\t=\t{0}",3>3);
49:
50: Console.WriteLine("1<=2\t=\t{0}",1<=2);
51: Console.WriteLine("2<=1\t=\t{0}",2<=1);
52: Console.WriteLine("3<=3\t=\t{0}",3<=3);
53: Console.WriteLine("1>=2\t=\t{0}",1>=2);
54: Console.WriteLine("2>=1\t=\t{0}",2>=1);
55: Console.WriteLine("3>=3\t=\t{0}",3>=3);
56:
57: Console.WriteLine("1==2\t=\t{0}",1==2);
58: Console.WriteLine("2==1\t=\t{0}",2==1);
59: Console.WriteLine("3==3\t=\t{0}",3==3);
60:
61: Console.WriteLine("1!=2\t=\t{0}",1!=2);
62: Console.WriteLine("2!=1\t=\t{0}",2!=1);
63: Console.WriteLine("3!=3\t=\t{0}",3!=3);
64:
65: Console.WriteLine("1 is int\t=\t{0}",1 is int);
66: Console.WriteLine("1.0 is int\t=\t{0}",1.0 is int);
67:
68: Console.WriteLine("false&false\t=\t{0}",false&false);
69: Console.WriteLine("true&false\t=\t{0}",true&false);
70: Console.WriteLine("true&true\t=\t{0}",true&true);
71:
72: Console.WriteLine("false^false\t=\t{0}",false^false);
73: Console.WriteLine("true^false\t=\t{0}",true^false);
74: Console.WriteLine("true^true\t=\t{0}",true^true);
75:
76: Console.WriteLine("false|false\t=\t{0}",false|false);
77: Console.WriteLine("true|false\t=\t{0}",true|false);
78: Console.WriteLine("true|true\t=\t{0}",true|true);
79:
80: Console.WriteLine("false ? 1 : 2\t=\t{0}",false ? 1 : 2);
81: Console.WriteLine("true ? 1 : 2\t=\t{0}",true ? 1 : 2);
82:
83: Console.WriteLine("+(2+3)\t=\t{0}",+(2+3));
84: Console.WriteLine("-(2+3)\t=\t{0}",-(2+3));
85:
86: Console.WriteLine("!true\t=\t{0}",!true);
87: Console.WriteLine("!false\t=\t{0}",!false);
88:
89: Console.WriteLine("★★ ビット演算(ビット表現がわかる人のみ)");
90: Console.WriteLine("256>>1\t=\t{0}",256>>1);
91: Console.WriteLine("256<<1\t=\t{0}",256<<1);
92:
93: Console.WriteLine("2147483647>>1\t=\t{0}",2147483647>>1);
94: Console.WriteLine("2147483647<<1\t=\t{0}",2147483647<<1);
95:
96: Console.WriteLine("2147483647u>>1\t=\t{0}",2147483647u>>1);
97: Console.WriteLine("2147483647u<<1\t=\t{0}",2147483647u<<1);
98:
99: Console.WriteLine("-2147483648>>1\t=\t{0}",-2147483648>>1);
100: Console.WriteLine("-2147483648<<1\t=\t{0}",-2147483648<<1);
101:
102: Console.WriteLine("1&3\t=\t{0}",1&3);
103: Console.WriteLine("1^3\t=\t{0}",1^3);
104: Console.WriteLine("1|3\t=\t{0}",1|3);
105:
106: Console.WriteLine("~1\t=\t{0}",~1);
107: Console.WriteLine("~1u\t=\t{0}",~1u);
108: Console.WriteLine("~-1\t=\t{0}",~-1);
109:
110: Console.WriteLine("★★ 変数の値を変える演算子(ソースと見比べて理解しよう)");
111: int x=0; Console.WriteLine("set x=0");
112: Console.WriteLine("++x\t=\t{0}",++x);
113: Console.WriteLine("++x\t=\t{0}",++x);
114: Console.WriteLine("++x\t=\t{0}",++x);
115:
116: x=0; Console.WriteLine("set x=0");
117: Console.WriteLine("x++\t=\t{0}",x++);
118: Console.WriteLine("x++\t=\t{0}",x++);
119: Console.WriteLine("x++\t=\t{0}",x++);
120:
121: x=0; Console.WriteLine("set x=0");
122: Console.WriteLine("--x\t=\t{0}",--x);
123: Console.WriteLine("--x\t=\t{0}",--x);
124: Console.WriteLine("--x\t=\t{0}",--x);
125:
126: x=0; Console.WriteLine("set x=0");
127: Console.WriteLine("x--\t=\t{0}",x--);
128: Console.WriteLine("x--\t=\t{0}",x--);
129: Console.WriteLine("x--\t=\t{0}",x--);
130:
131: x=0; Console.WriteLine("set x=0");
132: Console.WriteLine("x=1\t=\t{0}", x=1 );
133: Console.WriteLine("x is now {0}",x);
134:
135: x = 1;
136: x += 2;
137: Console.WriteLine("x=1; x+=2; value of x is {0}", x );
138: x = 1;
139: x -= 2;
140: Console.WriteLine("x=1; x-=2; value of x is {0}", x );
141: x = 2;
142: x *= 3;
143: Console.WriteLine("x=2; x*=3; value of x is {0}", x );
144: x = 6;
145: x /= 2;
146: Console.WriteLine("x=6; x/=2; value of x is {0}", x );
147: x = 6;
148: x %= 2;
149: Console.WriteLine("x=6; x%=2; value of x is {0}", x );
150: x = 6;
151: x <<= 2;
152: Console.WriteLine("x=6; x<<=2; value of x is {0}", x );
153: x = 6;
154: x >>= 2;
155: Console.WriteLine("x=6; x>>=2; value of x is {0}", x );
156: x = 1;
157: x &= 3;
158: Console.WriteLine("x=1; x&=3; value of x is {0}", x );
159: x = 1;
160: x ^= 3;
161: Console.WriteLine("x=1; x^=3; value of x is {0}", x );
162: x = 1;
163: x |= 3;
164: Console.WriteLine("x=1; x|=3; value of x is {0}", x );
165:
166: Console.WriteLine("★★ 式を処理しない場合がある演算子(ソースと見比べて理解しよう)");
167: x=0; Console.WriteLine("set x=0");
168: Console.WriteLine("returnFalse(x++) && returnFalse(x++)\t=\t{0}",returnFalse(x++) && returnFalse(x++));
169: Console.WriteLine("x is now {0}",x);
170: x=0; Console.WriteLine("set x=0");
171: Console.WriteLine("returnTrue(x++) && returnTrue(x++)\t=\t{0}",returnTrue(x++) && returnTrue(x++));
172: Console.WriteLine("x is now {0}",x);
173: x=0; Console.WriteLine("set x=0");
174: Console.WriteLine("returnFalse(x++) || returnFalse(x++)\t=\t{0}",returnFalse(x++) || returnFalse(x++));
175: Console.WriteLine("x is now {0}",x);
176: x=0; Console.WriteLine("set x=0");
177: Console.WriteLine("returnTrue(x++) || returnTrue(x++)\t=\t{0}",returnTrue(x++) || returnTrue(x++));
178: Console.WriteLine("x is now {0}",x);
179:
180: return 0;
181: }
182: }
183: };
|
|