---
title: BITAND – หา Bitwise AND ของสองตัวเลข
url: https://www.thepexcel.com/functions/excel/engineering/bitand/
type: function-explainer
program: Excel
syntax: "=BITAND(number1, number2)"
date: 2025-12-02
updated: 2025-12-24
scores:
  popularity: 3
  difficulty: 5
  usefulness: 4
---

# BITAND – หา Bitwise AND ของสองตัวเลข

> BITAND ใช้เปรียบเทียบเลข 2 ตัวในระดับบิต (bit-by-bit comparison) ผลลัพธ์จะเป็น 1 ก็ต่อเมื่อตำแหน่งบิ

## คำอธิบาย

BITAND ใช้เปรียบเทียบเลข 2 ตัวในระดับบิต (bit-by-bit comparison) ผลลัพธ์จะเป็น 1 ก็ต่อเมื่อตำแหน่งบิตนั้น 'เป็น 1 ทั้งคู่' เท่านั้น

## Syntax

```excel
=BITAND(number1, number2)
```

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| number1 | Yes | Number |  | ตัวเลขแรก (ต้องเป็นจำนวนเต็มที่ >= 0 และ < 2^48) |
| number2 | Yes | Number |  | ตัวเลขที่สอง (ต้องเป็นจำนวนเต็มที่ >= 0 และ < 2^48) |

## ตัวอย่าง

### 1. ตรวจสอบบิตพื้นฐาน

```excel
=BITAND(5, 3)
```

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

5 เป็น 101 (ไบนารี), 3 เป็น 011 (ไบนารี) เมื่อ AND กัน ได้ 001 = 1 เพราะบิตแรก (2^0) ของทั้งคู่เป็น 1

### 2. ตรวจสอบสถานะ (Permission Check)

```excel
=IF(BITAND(UserFlags, 4)=4, "Admin", "User")
```

**ผลลัพธ์:** `"Admin" หรือ "User"`

ถ้า UserFlags มีบิต 2^2 (ค่า 4) เปิด = มีสิทธิ Admin ใช้กับการตรวจสอบ flags/permissions ในระบบ

### 3. เปรียบเทียบตัวเลขหลายบิต

```excel
=BITAND(13, 25)
```

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

13 = 01101, 25 = 11001 AND กัน = 01001 (ซึ่งเป็น 8+1 = 9)

### 4. ตรวจสอบบิตเดี่ยว

```excel
=BITAND(Status, 2)=2
```

**ผลลัพธ์:** `TRUE หรือ FALSE`

ตรวจสอบว่าบิตที่ 2 (ค่า 2) ถูกเปิดอยู่หรือไม่ โดยเปรียบเทียบผลลัพธ์กับ 2

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

- ใช้ BITAND เพื่อตรวจสอบว่าบิตเฉพาะตำแหน่งถูกเปิดหรือปิด เทคนิค: =BITAND(number, power_of_2)=power_of_2 แล้วจะได้ TRUE/FALSE

- ค่า powers of 2 (1, 2, 4, 8, 16, 32...) มีประโยชน์มากเมื่อใช้กับ BITAND เพราะแต่ละตัวตรงกับบิตตำแหน่งเดียว

- BITAND มีประสิทธิภาพและทำงานเร็ว ใช้ได้กับเซลล์เดี่ยวหรือ array formula ได้ สูตรจะคำนวณอย่างรวดเร็ว

- หากต้องเปรียบเทียบหลายบิตพร้อมกัน ใช้เลขที่เป็น binary mask เช่น =BITAND(number, 255) เพื่อดึงเอาแค่ 8 บิตแรก

- รวม BITAND กับ IF เพื่อสร้าง logic สำหรับตรวจสอบ flags ตัวอย่าง: =IF(BITAND(status, 4)>0, "Yes", "No")

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

**Q: BITAND กับ BITOR ต่างกันอย่างไร**

BITAND ผลลัพธ์เป็น 1 ก็ต่อเมื่อ **ทั้งคู่** เป็น 1 (AND logic) ส่วน BITOR ผลลัพธ์เป็น 1 ถ้า **อย่างน้อย 1 ตัว** เป็น 1 (OR logic) ตัวอย่าง: BITAND(5,3)=1 แต่ BITOR(5,3)=7

**Q: BITAND ใช้ได้กับเลขลบไหม**

ไม่ได้ BITAND ต้องใช้กับจำนวนเต็มบวก >= 0 เท่านั้น ถ้าใส่เลขลบจะ error #NUM!

**Q: ตัวเลขสูงสุดที่ BITAND ใช้ได้คือเท่าไร**

ตัวเลขสูงสุดคือ (2^48)-1 = 281,474,976,710,655 ถ้าเกินจะ error #NUM!

**Q: BITAND ใช้ทำอะไรในการทำงานจริง**

ใช้ตรวจสอบ permission bits, feature flags, file attributes ตัวอย่าง: เช็คว่าไฟล์มีสิทธิ read/write/execute หรือไม่ หรือเช็คว่าผู้ใช้มี role ชนิดไหน

**Q: =BITAND(15, 8) ได้ผลลัพธ์เท่าไร**

8 เพราะ 15 = 1111, 8 = 1000 AND กัน = 1000 = 8

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

- [AND – ตรวจสอบเงื่อนไขทั้งหมดว่าเป็นจริง](https://www.thepexcel.com/functions/excel/logical/and/)
- [BITOR – หาค่า Bitwise OR](https://www.thepexcel.com/functions/excel/engineering/bitor/)
- [BITXOR – หาค่า Bitwise XOR ของตัวเลข](https://www.thepexcel.com/functions/excel/engineering/bitxor/)
- [DEC2BIN – แปลงตัวเลขฐาน 10 เป็นฐาน 2](https://www.thepexcel.com/functions/excel/engineering/dec2bin/)

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

- [Microsoft Excel - BITAND Function](https://support.microsoft.com/en-us/office/bitand-function-8a2be3d7-91c3-4b48-9517-64548008563a) _(official)_
- [Bitwise Operations in Excel](https://support.microsoft.com/en-us/office/bitwise-operations-in-excel-6f5cee22-ea15-4a0f-bcb9-ed6edc71dbf3) _(official)_

---

_Source: [https://www.thepexcel.com/functions/excel/engineering/bitand/](https://www.thepexcel.com/functions/excel/engineering/bitand/)_
