Skip to main content
gamedev.net
🔒 Locked

Bitwise value switching

Started by FenixRoA Nov 22, 2004 at 4:34 PM 1 replies 300+ views
Original Post
FenixRoA
FenixRoA
I once heard of a method to switch 2 variables without using a third variable using only 2 bitwise XOR statements. Is anyone familiar with this?
Mezz
Mezz
I'm not familiar with doing it in 2 XOR statements, but 3...

x = x ^ y;
y = x ^ y;
x = x ^ y;

-Mezz

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.