Worth spreading

빅 엔디안과 리틀 엔디안 (Big endian and little endian) 본문

Worth spreading

빅 엔디안과 리틀 엔디안 (Big endian and little endian)

annual 2018. 5. 12. 16:42


 빅 엔디안과 리틀 엔디안은 컴퓨터 메모리에 저장된 바이트들의 순서를 설명하는 용어이다. 빅 엔디안은 큰 쪽 (바이트 열에서 가장 큰 값)이 먼저 저장되는 순서이며, 리틀 엔디안은 작은 쪽 (바이트 열에서 가장 작은 값)이 먼저 저장되는 순서이다. 예를 들면, 빅 엔디안 컴퓨터에서는 16진수 "4F52"를 저장공간에 "4F52"라고 저장할 것이다 (만약 4F가 1000번지에 저장되었다면, 52는 1001번지에 저장될 것이다). 반면에, 리틀 엔디안 시스템에서 이것은 "524F"와 같이 저장될 것이다. 

IBM 370 컴퓨터와 대부분의 RISC 기반의 컴퓨터들, 그리고 모토로라 마이크로프로세서는 빅 엔디안 방식을 사용한다. 왼쪽에서 오른쪽으로 읽는 언어를 사용하는 사람들에게, 이것은 일련의 문자나 숫자를 저장하는 데 있어 자연스러운 방식이다. 

한편, 인텔 프로세서나 DEC의 알파 프로세서, 그리고 적어도 그것들 상에서 운영되는 일부 프로그램들은 리틀 엔디안을 사용한다. 리틀 엔디안 순서에 대한 논리는, 수의 값을 증가시킬 때 수의 왼편에 자릿수를 추가해야할 필요가 있을지 모른다는 것이다 (지수가 아닌 경우에, 더 큰 숫자는 더 많은 자릿수를 갖는다). 빅 엔디안으로 정렬되어 저장되어 있는 숫자는 두 숫자를 더한 결과를 저장하기 위해 모든 자릿수를 오른쪽으로 옮겨야하는 일이 종종 발생한다. 그러나 리틀 엔디안 방식으로 저장된 숫자에서는, 최소 바이트가 원래 있던 자리에 그대로 머물 수 있으며, 새로운 자리 수는 최대 수가 있는 주소의 오른쪽에 추가될 수 있다. 이것은 일부 컴퓨터 연산들이 매우 단순해지고 빠르게 수행될 수 있다는 것을 의미한다. 

자바나 포트란과 같은 컴파일러들은 그들이 개발하는 목적 코드가 어떤 방식으로 저장될 것인지를 알아야만 한다. 필요한 경우, 한 방식에서 다른 방식으로 변경하는데 변환기가 사용될 수도 있다. 

바이트 순서가 빅 엔디안이든 리틀 엔디안 이든, 각 바이트 내에 들어있는 비트들은 둘 모두 빅 엔디안으로 정렬되어 있다는 데에 유의하라. 즉, 저장된 바이트의 주어진 숫자에 의해 표현되는 전체적인 비트 스트림에 관해서는 빅이나 리틀 엔디안으로 하려는 시도가 없다는 것이다. 예를 들어 16진수 4F가 저장공간 내에 주어진 저장 주소범위 내에 있는 다른 바이트들과 함께 처음에 저장되든 또는 나중에 저장되든 간에, 그 바이트 내의 비트 순서는 다음과 같을 것이다. 

 01001111

비트 순서에 대해서도 빅 엔디안이나 리틀 엔디안으로 구현하는 것이 가능하긴 하지만, 거의 모든 CPU나 프로그램들은 빅 엔디안 비트 순서로 설계된다. 그러나 데이터 통신에서는, 비트 순서를 둘 중 어느 한쪽으로 하는 것이 가능하다. 

에릭 레이몬드(Eric Raymond)는 인터넷 도메인 이름과 전자우편 주소들이 리틀 엔디안 방식으로 표현된 것이라고 말한다. 예를 들어 만약, 이 블로그의 주소를 빅 엔디안 방식으로 쓴다면 다음과 같은 형식을 가질 것이다. 

com.tistory.worthpreading

빅 엔디안과 리틀 엔디안이라는 용어는 조나단 스위프트의 걸리버 여행기로부터 파생되었다. 빅엔디안은 "달걀의 작은 부분부터 깨야한다(Little Endians)"는 릴리푸티안 왕의 의견에 "달걀의 큰 부분 부터 깨야한다(Big-Endians)"고 반기를 든 것이다.


원문

Big-endian and little-endian derive from Jonathan Swift's Gulliver's Travels in which the Big Endians were a political faction that broke their eggs at the large end ("the primitive way") and rebelled against the Lilliputian King who required his subjects (the Little Endians) to break their eggs at the small end. 


 Big-endian and little-endian are terms that describe the order in which a sequence of bytes are stored in computer memory. Big-endian is an order in which the "big end" (most significant value in the sequence) is stored first (at the lowest storage address). Little-endian is an order in which the "little end" (least significant value in the sequence) is stored first. For example, in a big-endian computer, the two bytes required for the hexadecimal number 4F52 would be stored as 4F52 in storage (if 4F is stored at storage address 1000, for example, 52 will be at address 1001). In a little-endian system, it would be stored as 524F (52 at address 1000, 4F at 1001).

IBM's 370 mainframes, most RISC-based computers, and Motorola microprocessors use the big-endian approach. TCP/IP also uses the big-endian approach (and thus big-endian is sometimes called network order). For people who use languages that read left-to-right, this seems like the natural way to think of a storing a string of characters or numbers - in the same order you expect to see it presented to you. Many of us would thus think of big-endian as storing something in forward fashion, just as we read.

On the other hand, Intel processors (CPUs) and DEC Alphas and at least some programs that run on them are little-endian. An argument for little-endian order is that as you increase a numeric value, you may need to add digits to the left (a higher non-exponential number has more digits). Thus, an addition of two numbers often requires moving all the digits of a big-endian ordered number in storage, moving everything to the right. In a number stored in little-endian fashion, the least significant bytes can stay where they are and new digits can be added to the right at a higher address. This means that some computer operations may be simpler and faster to perform.

Language compilers such as that of Java or FORTRAN have to know which way the object code they develop is going to be stored. Converters can be used to change one kind of endian to the other when necessary.

Note that within both big-endian and little-endian byte orders, the bits within each byte are big-endian. That is, there is no attempt to be big- or little-endian about the entire bit stream represented by a given number of stored bytes. For example, whether hexadecimal 4F is put in storage first or last with other bytes in a given storage address range, the bit order within the byte will be:

 01001111

It is possible to be big-endian or little-endian about the bit order, but CPUs and programs are almost always designed for a big-endian bit order. In data transmission, however, it is possible to have either bit order.

Eric Raymond observes that Internet domain name addresses and e-mail addresses are little-endian. For example, a big-endian version of our domain name address would be:

 com.whatis.www

Big-endian and little-endian derive from Jonathan Swift's Gulliver's Travels in which the Big Endians were a political faction that broke their eggs at the large end ("the primitive way") and rebelled against the Lilliputian King who required his subjects (the Little Endians) to break their eggs at the small end.


An excerpt from "https://searchnetworking.techtarget.com/definition/big-endian-and-little-endian"

Comments