December 14, 2017

What is the endian, Little-endian and Big-endian


Endianness  엔디안 : It is the method for arranging data in a computer memory which is a one-dimensional space.
1차원 공간인 컴퓨터 메모리에 데이터를 배치하는 방법.


< endian.c >

#include <stdio.h>

int main() {
    char *abc = "abcd";
    printf("%s \n", abc);
    int num = 255;  // 0xff
    printf("%d \n", num);
}

< Ubuntu with Intel >

❑ Little-endian  리틀 엔디안
❍ When a value is entered into memory, the low digit is written in the low address.
낮은 자릿수를 낮은 주소에 저장하는 방식.
❍ Characters don't have a low digit concept and are stored in order from the low address.
문자는 낮은 자릿수 개념이 없으며 낮은 주소부터 차례로 저장된다.
❍ If you want to store 0x08048035 in memory, input it in reverse.
만약 0x08048035를 입력하고 싶으면 순서를 뒤집어 입력한다.
* python -c 'print "\x35\x80\x04\x08"' | ./endian
❍ 32-bit operating system uses reversed data in 4-byte units. 64-bit operating system uses reversed data in 8-byte units.
32비트 운영체제는 4바이트 단위로 뒤집힌 데이터를 이용하고, 64비트 운영체제는 8바이트 단위로 뒤집힌 데이터를 이용한다.
❍ It is used in Intel CPU.
인텔 계열 CPU에서 사용된다.




< Debian with SPARC >

❑ Big-endian  빅 엔디안
❍ When a value is entered into memory, the high digit is written in the low address.높은 자릿수를 낮은 주소에 저장하는 방식.
❍ Characters don't have a low digit concept and are stored in order from the low address.
문자는 낮은 자릿수 개념이 없으며 낮은 주소부터 차례로 저장된다.
❍ If you want to store 0x08048035 in memory, input it in order by 1byte.
* python -c 'print "\x08\x04\x80\x35"' | ./endian
❍ 32-bit operating system uses forward data in 4-byte units. 64-bit operating system uses forward data in 8-byte units.
32비트 운영체제는 4바이트 단위로 정방향 데이터를 이용하고, 64비트 운영체제는 8바이트 단위로 정방향 데이터를 이용한다.
❍ It is used in SPARC, RISC CPU.
SPARC, RISC 계열의 CPU에서 사용된다.


❑ In comparison, it is known that either side is not overwhelmingly good or bad.
비교 시 어느 한쪽이 압도적으로 좋거나 나쁘지 않다고 알려져 있음.
❑ Intel x86 based CPUs mainly use little-endian.
Intel x86 계열의 CPU는 주로 리틀 엔디안을 사용.
❑ Motorola based CPUs mainly use big-endian.
모토로라 계열의 CPU는 주로 빅 엔디안을 사용.
❑ ARM-based CPUs can choose between big endian and little endian.
ARM 계열의 CPU는 빅 엔디안, 리틀 엔디안을 선택할 수 있음.