본문 바로가기

C#/데이터 갖고 놀기4

[C#]데이터 마무리 namespace CSharp { class Program { static void Main(string[] args) { int a = 3 + ((2 * 3) ^ 4); // 우선 순위 // 1. ++ -- // 2. * / % // 3. + - // 4. > // 5. // 6. == != // 7. & // 8. ^ // 9. | // .. var num = 3; var num2 = "Hello World"; // 알아서 형 컴파일, 남용하지 말 것 } } } 2021. 3. 25.
[C#]비트 연산 namespace CSharp { class Program { static void Main(string[] args) { int id = 123; int key = 401; int a = id ^ key; int b = a ^ key; // > &(and) |(or) ^(xor : 두 값이 다를 경우 1) ~(not : 바꿔치기) Console.WriteLine(a); Console.WriteLine(b); } } } 2021. 3. 25.
[C#]데이터 연산 namespace CSharp { class Program { static void Main(string[] args) { int hp = 100; Console.WriteLine(hp++); // >= != == bool isAlive = (hp > 0); bool isHighLevel = (isHighLevel >= 40); // && AND || OR ! NOT // a = 살아있는 고렙 유저인가요? bool a = isAlive && isHighLevel; // b = 살아있거나, 고렙 유저이거나, 둘 중 하나인가요? bool b = isAlive || isHighLevel; //c = 죽은 유저인가요? bool c = !isAlive; } } } 2021. 3. 25.
[C#] 정수 형식, 진수 변환 등 using System; namespace CSharp { class Program { //여기에 주석을 달 수 있음 /* 사이에 주석을 달 수 있습니다. 여러 줄 짜리 주석*/ static void Main(string[] args) { // 데이터 + 로직 // 체력 0 // 1. 바구니 크기가 다른 경우! int a = 0xFFFF; short b = (short)a; // 2. 바구니 크기는 같긴 한데, 부호가 다를 경우 byte c = 255; sbyte sb = (sbyte)c; // underflow, overflow // 0xFF = 0b11111111 = -1 // 3.소수 float f = 3.1414f; double d = f; // byte(1바이트 0~255), short(2바이트.. 2021. 3. 23.