Thep Excel

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

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

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

ความนิยม2/10
ความยาก2/10
ประโยชน์2/10

อัปเดต 4 December 2025

Syntax & Arguments

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

How it works

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

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

Examples

ตัวอย่างที่ 1: Little Endian ทำให้ {1,0} เป็น 1let Bytes = Binary.FromList({1, 0}), Fmt = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.LittleEndian), Value = Fmt(Bytes) in Value

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

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

ผลลัพธ์1
ตัวอย่างที่ 2: Big Endian ทำให้ {1,0} เป็น 256let Bytes = Binary.FromList({1, 0}), Fmt = BinaryFormat.ByteOrder(BinaryFormat.UnsignedInteger16, ByteOrder.BigEndian), Value = Fmt(Bytes) in Value

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

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

ผลลัพธ์256
ตัวอย่างที่ 3: ถ้าไม่ระบุอาจได้ค่าแบบค่าเริ่มต้นlet Bytes = Binary.FromList({1, 0}), Value = BinaryFormat.UnsignedInteger16(Bytes) in Value

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

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

ผลลัพธ์256

FAQs

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

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

Resources & Related

ฟังก์ชันที่ผู้เขียนโยงไว้กับ ByteOrder.Type จัดกลุ่มตามหมวด · ชี้ที่ชื่อใดชื่อหนึ่ง แล้วฟังก์ชันที่ใช้คู่กันจะมีจุดทอง

ฟังก์ชันนี้ByteOrder.Typeenumerations
Binary functions (1)
BinaryFormat.ByteOrder

BinaryFormat.ByteOrder ระบุลำดับไบต์ (Big Endian หรือ Little Endian) สำหรับการอ่านข้อมูล

Comments

อีเมลของคุณจะไม่ถูกเผยแพร่