---
title: BITXOR – คำนวณ XOR แบบบิต (Bitwise XOR)
url: https://www.thepexcel.com/functions/dax/logical/bitxor-dax/
type: function-explainer
program: DAX
syntax: "BITXOR(<Number1>, <Number2>)"
date: 2025-12-13
updated: 2025-12-17
scores:
  popularity: 2
  difficulty: 3
  usefulness: 2
---

# BITXOR – คำนวณ XOR แบบบิต (Bitwise XOR)

> ทำ XOR แบบบิตระหว่างตัวเลขสองค่า

## คำอธิบาย

BITXOR คืนผลลัพธ์ของ XOR แบบบิตระหว่าง Number1 และ Number2 เหมาะกับการสลับแฟลก (toggle) ในงานที่ใช้ bitmask

## Syntax

```excel
BITXOR(&lt;Number1&gt;, &lt;Number2&gt;)
```

**Variant**

```excel
BITXOR(&lt;Number1&gt;, &lt;Number2&gt;)
```

คืนผลลัพธ์ของ XOR แบบบิตระหว่าง 2 ตัวเลข

## Arguments

| Name | Required | Type | Default | Description |
| --- | --- | --- | --- | --- |
| Number1 | Yes | number |  | ตัวเลขตัวแรก (เช่น ค่า flags เดิม) |
| Number2 | Yes | number |  | ตัวเลขตัวที่สอง (เช่น mask ของแฟลกที่ต้องการสลับ) |

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

### สลับแฟลก (toggle) ของบิตที่กำหนด

เปิดถ้ายังไม่เปิด หรือปิดถ้าเปิดอยู่

_เหมาะกับ:_ toggle-flag

### หาค่าที่ต่างกันระหว่าง 2 bitmask

คืนบิตที่ต่างกันเพื่อใช้วิเคราะห์

_เหมาะกับ:_ diff-mask

## ตัวอย่าง

### 1. ตัวอย่างที่ 1: สลับแฟลก 4

```excel
Flags (Toggle 4) =
BITXOR([Flags], 4)
```

**ผลลัพธ์:** `ได้ค่า flags ใหม่ที่สลับสถานะของแฟลก 4`

ถ้าแฟลก 4 เปิดอยู่จะถูกปิด และถ้าปิดอยู่จะถูกเปิด

### 2. ตัวอย่างที่ 2: หาบิตที่ต่างกันระหว่าง 2 ค่า

```excel
Different Bits =
BITXOR(13, 6)
```

**ผลลัพธ์:** `คืนค่าตัวเลขที่แทนบิตที่ต่างกัน`

ใช้ดูความแตกต่างของสอง bitmask โดยผลลัพธ์เป็นบิตที่ไม่เหมือนกัน

### 3. ตัวอย่างที่ 3: สลับหลายแฟลกพร้อมกัน

```excel
Flags (Toggle 1 and 8) =
BITXOR([Flags], 9)
```

**ผลลัพธ์:** `สลับแฟลก 1 และ 8 พร้อมกัน`

ค่า 9 คือ mask ที่รวมแฟลก 1 และ 8 เมื่อ XOR จะสลับทั้งสองบิตพร้อมกัน

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

ถ้าต้องการเปิดบิตโดยไม่เปลี่ยนบิตอื่น ให้ใช้ BITOR และถ้าต้องการตรวจว่ามีบิตเปิดอยู่หรือไม่ ให้ใช้ BITAND

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

**Q: BITXOR ใช้ทำอะไรได้เด่นที่สุด?**

เด่นเรื่องการสลับแฟลก (toggle) เพราะ XOR จะเปลี่ยนสถานะของบิตที่ระบุใน mask เสมอ

**Q: BITXOR ต่างจาก BITOR อย่างไร?**

BITOR ใช้เปิดบิต (รวมแฟลก) ส่วน BITXOR ใช้สลับบิต (เปิด/ปิดสลับกัน)

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

- [BITAND – คำนวณ AND แบบบิต (Bitwise AND)](https://www.thepexcel.com/functions/dax/logical/bitand-dax/)
- [BITOR – คำนวณ OR แบบบิต (Bitwise OR)](https://www.thepexcel.com/functions/dax/logical/bitor-dax/)
- [AND – ตรวจสอบเงื่อนไขตรรกะในDAX](https://www.thepexcel.com/functions/dax/logical/and-dax/)
- [OR – ตรวจสอบว่ามีเงื่อนไขใดเป็นจริง](https://www.thepexcel.com/functions/dax/logical/or-dax/)
- [NOT – กลับค่าตรรกะ (TRUE/FALSE)](https://www.thepexcel.com/functions/dax/logical/not-dax/)
- [IF – ตรวจสอบเงื่อนไขและคืนค่าตามผลลัพธ์ TRUE/FALSE](https://www.thepexcel.com/functions/dax/logical/if-dax/)

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

- [DAX Guide: BITXOR](https://dax.guide/bitxor/) _(documentation)_

---

_Source: [https://www.thepexcel.com/functions/dax/logical/bitxor-dax/](https://www.thepexcel.com/functions/dax/logical/bitxor-dax/)_
