---
title: ByteOrder.Type – ลำดับไบต์ (Little Endian / Big Endian)
url: https://www.thepexcel.com/functions/power-query/enumerations/byteorder-type/
type: function-explainer
program: Power Query
syntax: "BinaryFormat.ByteOrder(binaryFormat, ByteOrder.LittleEndian|BigEndian)"
date: 2025-12-04
updated: 2025-12-17
scores:
  popularity: 2
  difficulty: 2
  usefulness: 2
---

# ByteOrder.Type – ลำดับไบต์ (Little Endian / Big Endian)

> ชุดค่าคงที่สำหรับกำหนด Endian ของข้อมูลไบนารี

## คำอธิบาย

ByteOrder.Type เป็นชุดค่าคงที่สำหรับกำหนดลำดับไบต์ของข้อมูลไบนารี โดย ByteOrder.LittleEndian หมายถึงไบต์น้อย (least significant byte) มาก่อน และ ByteOrder.BigEndian หมายถึงไบต์มาก (most significant byte) มาก่อน ค่านี้ใช้เป็นพารามิเตอร์ byteOrder ของ BinaryFormat.ByteOrder เพื่อให้การอ่านค่าเลขจากไบนารีถูกต้อง

## Syntax

```excel
BinaryFormat.ByteOrder(binaryFormat, ByteOrder.LittleEndian|BigEndian)
```

## เคสการใช้งาน

### อ่านเลข 16-bit จากไบนารีให้ถูก Endian

เมื่อรับไฟล์/สตรีมไบนารีจากระบบอื่น ให้กำหนด ByteOrder ให้ตรงกับรูปแบบของไฟล์ เพื่อหลีกเลี่ยงการอ่านค่าเพี้ยน

_เหมาะกับ:_ binary-endian

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: Little Endian ทำให้ {1,0} เป็น 1

```excel
let Bytes = Binary.FromList({1, 0}), Fmt = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian), Value = Fmt(Bytes) in Value
```

**ผลลัพธ์:** `1`

กำหนด ByteOrder.LittleEndian แล้วอ่าน UnsignedInteger16 จากไบนารี {1,0} จะได้ค่า 1 เพราะไบต์น้อยมาก่อน

### 2. ตัวอย่างที่ 2: Big Endian ทำให้ {1,0} เป็น 256

```excel
let Bytes = Binary.FromList({1, 0}), Fmt = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.BigEndian), Value = Fmt(Bytes) in Value
```

**ผลลัพธ์:** `256`

กำหนด ByteOrder.BigEndian แล้วอ่าน UnsignedInteger16 จากไบนารีเดียวกัน {1,0} จะได้ 256 เพราะไบต์มากมาก่อน

### 3. ตัวอย่างที่ 3: ถ้าไม่ระบุอาจได้ค่าแบบค่าเริ่มต้น

```excel
let Bytes = Binary.FromList({1, 0}), Value = BinaryFormat.UnsignedInteger16(Bytes) in Value
```

**ผลลัพธ์:** `256`

บาง BinaryFormat ใช้ค่าเริ่มต้นเป็น Big Endian ตามเอกสาร จึงควรกำหนด ByteOrder ให้ชัดเจนเมื่อรูปแบบไฟล์เป็น Little Endian

## หมายเหตุเพิ่มเติม

ค่า ByteOrder.* เป็นค่าตัวเลข (0/1) ที่ใช้เป็นพารามิเตอร์ byteOrder ของ BinaryFormat.ByteOrder เพื่อควบคุมการตีความไบต์

## คำถามที่พบบ่อย

**Q: ควรเลือก Little Endian หรือ Big Endian ยังไง?**

ให้ดูสเปกของไฟล์/โปรโตคอลต้นทาง ถ้าระบุว่า Little Endian ให้ใช้ ByteOrder.LittleEndian ถ้าเป็น Big Endian ให้ใช้ ByteOrder.BigEndian เพื่ออ่านค่าเลขถูกต้อง

## ฟังก์ชันที่เกี่ยวข้อง

- [BinaryFormat.ByteOrder – ลำดับไบต์](https://www.thepexcel.com/functions/power-query/binary-functions/binaryformat-byteorder/)
- [BinaryFormat.UnsignedInteger16 – จำนวนเต็มไม่มีเครื่องหมาย 16 บิต](https://www.thepexcel.com/functions/power-query/binary-functions/binaryformat-unsignedinteger16/)
- [Binary.FromList – สร้างข้อมูลไบนารี่จากรายการ](https://www.thepexcel.com/functions/power-query/binary-functions/binary-fromlist/)

## แหล่งข้อมูลเพิ่มเติม

- [เอกสาร Microsoft Learn: ByteOrder.Type](https://learn.microsoft.com/en-us/powerquery-m/byteorder-type) _(documentation)_

---

_Source: [https://www.thepexcel.com/functions/power-query/enumerations/byteorder-type/](https://www.thepexcel.com/functions/power-query/enumerations/byteorder-type/)_
