Thep Excel

Binary.Length – ได้ความยาว Binary

ตรวจสอบจำนวน Bytes ในค่า Binary

Binary.Length ตรวจสอบและคืนค่าจำนวน Bytes ในค่า Binary เป็นตัวเลข เช่น Binary ที่มี 5 Bytes จะคืนค่า 5

=Binary.Length(binary as nullable binary) as nullable number

By ThepExcel AI Agent
4 December 2025

Syntax & Arguments

=Binary.Length(binary as nullable binary) as nullable number

Argument Type Required Default Description
binary binary Yes ค่า Binary (nullable) ที่ต้องการตรวจสอบความยาว (จำนวน Bytes)

How it works

ตรวจสอบขนาดไฟล์ Binary

ใช้ Binary.Length เพื่อตรวจสอบว่า Binary มีขนาดเป็นจำนวน Bytes เท่าไร ประโยชน์สำหรับตรวจสอบว่าไฟล์สมบูรณ์

ตรวจสอบความถูกต้องของข้อมูล

เช่น หากคาดว่า Binary ควรมีความยาว 256 Bytes แต่จริงๆได้ 255 Bytes แสดงว่าข้อมูลบกพร่อง

จัดกระทำข้อมูล Binary ตามขนาด

ใช้ Binary.Length ตัดสินใจว่าจะแบ่งหรือประมวลผล Binary ด้วยวิธีไหน

Examples

ตัวอย่างที่ 1: ตรวจสอบความยาวของ Binary ง่ายๆ

สร้าง Binary จากรายการตัวเลข {0, 1, 2, 3, 4} ซึ่งมี 5 ตัว ใช้ Binary.Length ตรวจสอบความยาว ได้ผลลัพธ์ 5
Power Query Formula:

=Binary.Length(Binary.FromList({0, 1, 2, 3, 4}))

Result:

5

ตัวอย่างที่ 2: ตรวจสอบความยาวข้อความแปลงเป็น Binary

แปลงข้อความ "Hello World" เป็น Binary (11 ตัวอักษร: H,e,l,l,o,space,W,o,r,l,d) ใช้ Binary.Length ได้ผลลัพธ์ 11
Power Query Formula:

let
    Text = "Hello World",
    BinaryData = Binary.FromText(Text),
    Length = Binary.Length(BinaryData)
in
    Length

Result:

11

ตัวอย่างที่ 3: ตรวจสอบความยาว Binary ว่างและ Binary ที่รวมกัน

สร้าง Binary ว่าง ตรวจสอบความยาว ได้ 0 จากนั้นรวม 2 Binary (Part1: 2 Bytes, Part2: 2 Bytes) เข้าเป็น Binary เดียว (4 Bytes รวม) ตรวจสอบความยาวของ Binary ที่รวมกันได้ 4
Power Query Formula:

let
    EmptyBinary = Binary.FromList({}),
    LengthEmpty = Binary.Length(EmptyBinary),
    Part1 = Binary.FromList({65, 66}),
    Part2 = Binary.FromList({67, 68}),
    Combined = Binary.Combine({Part1, Part2}),
    LengthCombined = Binary.Length(Combined)
in
    [EmptyLength = LengthEmpty, CombinedLength = LengthCombined]

Result:

[EmptyLength = 0, CombinedLength = 4]

FAQs

Binary.Length กับ Text.Length ต่างกันอย่างไร?

Binary.Length ตรวจสอบจำนวน Bytes ในข้อมูล Binary ส่วน Text.Length ตรวจสอบจำนวนตัวอักษรในข้อความ สำหรับข้อความภาษาอังกฤษ 1 ตัวอักษร = 1 Byte แต่ภาษาอื่นอาจต่างกัน

ถ้า Input เป็น null จะได้อะไร?

Binary.Length(null) จะคืนค่า null ตามหลักการ null propagation ของ Power Query

ความยาว Binary สูงสุดเท่าไร?

ไม่มีขีดจำกัดในเรื่องความยาว Binary แต่ขึ้นอยู่กับหน่วยความจำที่มีอยู่ใน Power Query

ใช้ Binary.Length ได้กับการตรวจสอบรูปแบบไฟล์หรือไม่?

ได้บางส่วน เช่น ตรวจสอบว่า Binary มีความยาวตามลักษณะเฉพาะของไฟล์ (Image header ควรมีความยาวเท่ากัน) แต่การตรวจสอบรูปแบบต้องตรวจสอบเนื้อหา (Signature bytes) ไม่ใช่แค่ความยาว

Resources & Related

Additional Notes

ฟังก์ชัน Binary.Length ใน Power Query ใช้สำหรับตรวจสอบจำนวน Bytes ในค่า Binary ผลลัพธ์คือตัวเลขที่แสดงความยาวของ Binary นับจาก Bytes ตัวแรกถึงตัวสุดท้าย เหมาะสำหรับการตรวจสอบขนาดข้อมูลหรือตรวจสอบข้อมูล Binary

Leave a Reply

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