비트 연산




 #include <iostream>



//Bit 비트


char AttackItem = 'a';

int DefenseItem = 2;

int Portion = 4;

int HealthPowqer = 8;


enum class Items :int

{

AttackItem = 1,

DefenseItem = 2,

Portion = 4,

HealthPowqer = 8


};


int PlayerItem = 0;




int main()

{

PlayerItem = PlayerItem | AttackItem;

PlayerItem = PlayerItem | DefenseItem;


//플레이어가 AttackItem을 갖고 있는지?


if ((PlayerItem & AttackItem) == AttackItem)

{


}


if ((PlayerItem & static_cast<int>(Items::AttackItem)) > 0)

{

std::cout << "플레이어는 어택아이템을 소유했습니다\n";

}


//비트 연산자

std::cout << (AttackItem) << "\n";

std::cout << (AttackItem<<2) << "\n";


system("pause");

}





0 comments:

댓글 쓰기