a, b 값 바꾸기(XOR,swap)

XOR 연산으로 a, b 값 서로 바꾸기

public class test0917 {
public static void main(String[] args){
int a = 5;
int b =3;

System.out.println(a+","+ b);  
System.out.println("a^=b :"+(a^=b));//6 0101 xor 0011 = 0110
System.out.println("b^=a :"+(b^=a));//5 0011 xor 0110 = 0101
System.out.println("a^=b :"+(a^=b));//3 0110 xor 0101 = 0011
System.out.println(a+","+ b);

}
}
-------------------------------------------------
5,3
a^=b :6
b^=a :5
a^=b :3
3,5

Popular posts from this blog

com.gpki.secureweb.GPKISecureWEBException: ErrCode=1507,ErrMsg=[GPKI_CMS_ProcessEnvelopedData] 해당 인증서로는 데이터를 풀 수 없습니다.

PL/SQL Developer Tip 선택한 것만 실행

전자정부 EgovMap Xml Jsp