> For the complete documentation index, see [llms.txt](https://krjaeh0.gitbook.io/j-log/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://krjaeh0.gitbook.io/j-log/programming/cs_basics/data_representation/number-systems-and-bits/byte_ordering.md).

# Byte\_Ordering

* 2 바이트 이상의 데이터는 메모리에 연속으로 저장된다.
* 이때 각 바이트가 메모리에 정렬되는 방식을 바이트 오더링(byte ordering)이라고 부른다.
* 두 방식으로 정리할 수 있다.
  * 빅 엔디안(Big Endian)
  * 리틀 엔디안(Little Endian)

{% hint style="info" %}

#### 바이트 오더링과 MSB, LSB

* 여러 자료에서 **MSB**, **LSB**를 이용하여 빅 엔디안, 리틀 엔디안을 설명하는 것을 종종 볼 수 있다.

* Significant **Bit**를 의미하는 것이 아니라, Significant **Byte**를 의미

* 바이트 오더링은 비트의 순서가 아니라 바이트의 순서를 고려하는 것으로, 바이트 내 비트의 순서는 동일하고 바이트의 순서만 달라진다.

* **가장 왼쪽에 있는 바이트**를 MSB(Most Significant **Byte**), **가장 오른쪽에 있는 바이트**를 LSB(Least Significant **Byte**)라고 표현했다고 이해하면 됨
  {% endhint %}

* **하단에 등장하는 이미지**들은 4 바이트 16진수 `0x01234567` (2진수 `0000 0001 0010 0011 0100 0101 0110 0111`)을 메모리 주소 `0x100`에 저장한 결과이다.

## 빅 엔디안 (Big-endian)

가장 왼쪽에 있는 바이트부터 메모리의 낮은 주소에 저장된다.

* 네트워크 상에서 데이터를 전송할 때는 빅 엔디안 방식을 따른다.
* 대표적으로 SPARC CPU에서 빅 엔디안을 사용한다.

## 리틀 엔디안 (Little-endian)

가장 오른쪽에 있는 바이트부터 메모리의 낮은 주소에 저장된다.

* 대표적으로 Intel x86, x86-64 CPU에서 리틀 엔디안을 사용
* 대다수의 개인용 컴퓨터 및 서버 환경에서 x86-64 CPU 아키텍처를 사용하는 만큼, 잘 알아야 한다.

## 문자열과 문자열이 아닌 데이터의 출력 형태

* 문자열은 메모리에 저장할 때 바이트 오더링을 고려하지 않는다. (문자 순서 그대로 메모리에 저장)
* 문자열이 아닌 데이터는 바이트 오더링에 따라 지정된 방식으로 저장된다.


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://krjaeh0.gitbook.io/j-log/programming/cs_basics/data_representation/number-systems-and-bits/byte_ordering.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
