Thep Excel

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

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

=BinaryFormat.ByteOrder(binaryFormat, ByteOrder.LittleEndian|BigEndian)

By ThepExcel AI Agent
4 December 2025

Function Metrics


Popularity
2/10

Difficulty
2/10

Usefulness
2/10

Syntax & Arguments

=BinaryFormat.ByteOrder(binaryFormat, ByteOrder.LittleEndian|BigEndian)

How it works

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

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

Examples

ตัวอย่างที่ 1: Little Endian ทำให้ {1,0} เป็น 1
let Bytes = Binary.FromList({1, 0}), Fmt = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian), Value = Fmt(Bytes) in Value
กำหนด ByteOrder.LittleEndian แล้วอ่าน UnsignedInteger16 จากไบนารี {1,0} จะได้ค่า 1 เพราะไบต์น้อยมาก่อน
Power Query Formula:

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

Result:

1

ตัวอย่างที่ 2: Big Endian ทำให้ {1,0} เป็น 256
let Bytes = Binary.FromList({1, 0}), Fmt = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.BigEndian), Value = Fmt(Bytes) in Value
กำหนด ByteOrder.BigEndian แล้วอ่าน UnsignedInteger16 จากไบนารีเดียวกัน {1,0} จะได้ 256 เพราะไบต์มากมาก่อน
Power Query Formula:

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

Result:

256

ตัวอย่างที่ 3: ถ้าไม่ระบุอาจได้ค่าแบบค่าเริ่มต้น
let Bytes = Binary.FromList({1, 0}), Value = BinaryFormat.UnsignedInteger16(Bytes) in Value
บาง BinaryFormat ใช้ค่าเริ่มต้นเป็น Big Endian ตามเอกสาร จึงควรกำหนด ByteOrder ให้ชัดเจนเมื่อรูปแบบไฟล์เป็น Little Endian
Power Query Formula:

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

Result:

256

FAQs

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

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

Resources & Related

Additional Notes

ByteOrder.Type คือชุดค่าคงที่ที่ใช้กำหนดลำดับไบต์ (Endian) เวลาตีความข้อมูลไบนารี เช่น Little Endian หรือ Big Endian โดยมักใช้เป็นพารามิเตอร์ให้กับ BinaryFormat.ByteOrder

Leave a Reply

Your email address will not be published. Required fields are marked *