
0: 양수, 1: 음수5 → 00000101, 5 → 11111010+0, 0이 존재함 → 사용 잘 안 함+1을 더함5 = 00000101반전 → 11111010+1 → 11111011 → 5+0, 0이 하나로 통합signed: 부호 있음 → 음수 + 양수unsigned: 양수만 → 더 넓은 양의 값 표현 가능예: int → short → 상위 비트 손실
| 타입 | 크기(Byte) | Signed 범위 | Unsigned 범위 |
|---|---|---|---|
| char | 1 | -128 ~ 127 | 0 ~ 255 |
| short | 2 | -32,768 ~ 32,767 | 0 ~ 65,535 |
| int | 4 | -2,147,483,648 ~ 2,147,483,647 | 0 ~ 4,294,967,295 |
| long long | 8 | -9경 ~ 9경 (±9,223,372조) | 0 ~ 18,446경 |
2진수 4자리 = 16진수 1자리
| 진법 | 설명 | 코드 표현 |
|---|---|---|
| 2진수 (BIN) | 컴퓨터 내부 기본 표현 | 0b1100 |
| 10진수 (DEC) | 사람이 일상 사용하는 표현 | 기본 숫자 |
| 16진수 (HEX) | 디버깅/주소 표현에 유용 | 0xF |
| 8진수 (OCT) | 예전 시스템에서 사용 | 거의 사용 안 함 |
| A | B | A+B | Carry |
|---|---|---|---|
| 0 | 0 | 0 | 0 |
| 1 | 0 | 1 | 0 |
| 1 | 1 | 0 | 1 (올림 발생) |
5 + 35: 000001013: 0000001100001000 → 85 - 3 = 5 + (-3)3의 2의 보수: 111111015 = 0000010100000010 → 22147483647 + 1 → 21474836482147483648 - 1 → 21474836470x12345678 → 메모리: 78 56 34 12#include <iostream>
using namespace std;
// 정수의 원리
// 비트 0,1 데이터의 최소 단위
// 바이트
// 1 바이트 -> 8bit
// 컴퓨터는 전기 신호로 숫자를 만들어줌
// 최상위 비트는 -를 담당함
// 1바이트의 가장 큰 값을 01111111 : 127
// 11111111 = 1
// 복습
int hp;
// 데이터 범위
short mp;
// 진법
// 0,1,2,3,4,5,6,7,8,9 -> 10 (1과 0으로 표현) 조합하면서 무한대 숫자를 만들 수 있음\
// 0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F 16 진법
// why? 16 진법
// 2진법과 궁합이 잘맞음
//
int main()
{
hp = 0xFF/*306189112*/;
mp = /*(short)*/hp; // 값을 꺼내옴 // 다른 숫자가 나옴 범위 밖의 숫자가 날아감
// 형변환이 필요함
cout << hp;
return 0;
}
5
멋지군요!! 칭찬합니다
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
if (a)
{
cout << "멋지군요!! 칭찬합니다" << endl;
}
return 0;
}
3
3 입력하셨군요
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
cout << a << " 입력하셨군요" << endl;
return 0;
}
3
3 3 3
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
cout << a << " " << a << " " << a << endl;
return 0;
}
3 5 9
333
555
999
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
cout << a << "" << a << "" << a << endl;
cout << b << "" << b << "" << b << endl;
cout << c << "" << c << "" << c << endl;
return 0;
}
30 10
두 숫자의 차는 20 입니다.
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << "두 숫자의 차는 " << a - b << " 입니다." << endl;
return 0;
}
5 2
5 + 2 = 7
5 * 2 = 10
5 / 2 = 2
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
cout << a << "+" << b << "=" <<a + b << endl;
cout << a << "*" << b << "=" <<a * b << endl;
cout << a << "/" << b << "=" <<a / b << endl;
return 0;
}
4 3
a가 b보다 크다
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
if (a > b)
{
cout << "a가 b보다 크다" << endl;
}
else
{
cout << "b가 a보다 같거나 크다" << endl;
}
return 0;
}
3 5
5555
#include <iostream>
using namespace std;
int main()
{
int a, b;
cin >> a >> b;
if (a > b)
{
cout << a << a << a << a << endl;
}
else if(b > a)
{
cout << b << b << b << b << endl;
}
else
{
}
return 0;
}
5
5를 입력함
a++을 수행하면 6이 됩니다
#include <iostream>
using namespace std;
int main()
{
int a;
cin >> a;
cout << a << " 를 입력함" << endl;
a++;
cout << "a++을 수행하면 " << a << "이 됩니다" << endl;
return 0;
}
5
6
#include <iostream>
using namespace std;
int main()
{
int input;
cin >> input;
if (input > 3)
{
input++;
cout << input << endl;
}
else if (input <= 3)
{
input--;
cout << input << endl;
}
return 0;
}
###
###
###
$$$
$$$
$$$
3
###
###
###
#include <iostream>
using namespace std;
int main()
{
int num;
cin >> num;
if (num > 0)
{
cout << "###" << endl;
cout << "###" << endl;
cout << "###" << endl;
}
else if (num < 0)
{
cout << "$$$" << endl;
cout << "$$$" << endl;
cout << "$$$" << endl;
}
else
{
}
return 0;
}
1 2 3
행운의 수
#include <iostream>
using namespace std;
int main()
{
int a, b, c;
cin >> a >> b >> c;
if ((a + b + c) >= (a * b * c))
{
cout << "행운의 수" << endl;
}
else
{
cout << "소소한 수" << endl;
}
return 0;
}