엔지니어가 되고 싶은 공돌이

04. Byte Ordering 본문

Computer Science/System Programming

04. Byte Ordering

Geca 2025. 2. 5. 14:23

 

4. 1. 32bit vs 64bit

 

- 컴퓨터에서 기본 데이터 처리 단위를 word라 부릅니다.

 

   과거에는 32bit 컴퓨터를 썼기에 word size는 32bit 였지만,

 

   오늘날 컴퓨터는 대부분 64bit 컴퓨터를 쓰기에, 오늘날 word size는 64bit 입니다.

 

 

- Virtual Memory도 32bit 컴퓨터에서는 4GB이지만, 64bit 컴퓨터에서는 16TB로 확장됩니다.

 

  이론적 크기는 264 = 16EB이지만 실제로는 이것보다 더 작은 크기를 사용합니다.

 

 

- Memory는 접근의 편의성을 위해 Address를 가지고 있습니다.

 

  32bit 컴퓨터는 4Byte 이므로 연속되는 word의 Address4씩 차이가 나고,

 

  64bit 컴퓨터는 8Byte 이므로 연속되는 word의 Address는 8씩 차이가 납니다.

 

 

- C 데이터 타입의 크기(Sizes of C Data Types)

 

  1) char : 1Byte.

 

  2) short: 2byte.

 

       int: 4Byte.

 

       long: 4Byte(32bit) or 8Byte(64bit).

 

       long long: 8Byte.

 

  3) float: 4Byte.

     

       double: 8Byte.

 

  4) Pointer(*): 4Byte(32bit) or 8Byte(64bit).

 


 

4. 2. Byte Ordering

 

- Byte Ordering: 연속적인 데이터를 메모리에 순서대로 저장하는 방법.

 

- Big Endian: 낮은 주소에 데이터의 MSB부터 저장하는 방식. (Sparc)

 

- Little Endian: 낮은 주소에 LSB부터 저장하는 방식. (x86, Intel)

 

  Ex) 0x12345678.

 

        Big Endian: 0x12, 0x34, 0x56, 0x78. 

 

        Little Endian: 0x78, 0x56, 0x34, 0x12.

 

 

- Network에서는 서로 다른 Endian을 쓰는 컴퓨터 끼리도 통신이 원할하게 될 수 있도록,

 

  Big Endian으로 통일해서 사용합니다.

 

 

- C에서 문자열(Character)은 배열에 저장하고, ASCII 코드로 인코딩 되어 있습니다.

 

  0은 0x30, 숫자 i는 0x30 + i, 문자열은 null(0)로 끝납니다.

 


'Computer Science > System Programming' 카테고리의 다른 글

06. Assembly 1: Basic Operations  (0) 2025.02.06
05. Program and Instruction Set  (0) 2025.02.06
03. Representation of Floating Points  (0) 2025.02.04
02. Representation of Integer  (0) 2025.02.03
01. Digital Systems  (0) 2025.02.03
Comments