시스템 프로그래밍 노트 1 - 기본 표현 단위와 정수 표현

2019년 10월 22일

1. 기본 표현 단위

모든 정보의 최소 표현 단위는 비트이다.

1.1. 비트 연산자

2. 정수

크게 unsigned와 Two’s Complement로 구분할 수 있다.

2.1. unsigned

B2U(X)=i=0w1xi2i B2U(X) = \sum _{i=0} ^{w-1} x_i \cdot 2^i

2.2. Two’s Complement

B2T(X)=xw12w1+i=0w2xi2i B2T(X) = -x_{w-1} \cdot 2^{w-1} + \sum _{i=0} ^{w-2} x_i \cdot 2^i

2.3. 변환

int tx, ty;
unsigned ux, uy;
tx = ux; // same as tx = (int) ux;
uy = ty; // same as uy = (unsigned) ty;

2.4. 확장/축소

short int x = -15213; // 0xc493
int ix = (int) x;     // 0xffffc493

2.5. 덧셈

2.6. 곱셈

2.7. Bitwise Shift

2.7.1. Left Shift

2.7.2. Right Shift

3. Byte Ordering

데이터 타입32비트64비트x86-64
char111
short222
int444
long488
float444
double888
long double--10/16
pointer488