Posts tagged "xor"

Method Swap – without temporary variable

ตัวอย่างข้างต้น เป็นการเขียนโปรแกรม swap ค่าแบบแปลกๆครับ ไม่ต้องมาสร้างตัวแปร temp อีกแย๊ว จะนำเสนอ 2 วิธีครับ วิธีแรก :: การใช้ Operator XOR ตัวอย่าง code สำหรับ ภาษา C# 1 2 3 4 5 void swap (ref int a, ref int b) { a ^= b; b ^= a; a ^= b; & ...

Read More