int Fire = 1;
int Rock = 2;
int Wind = 3;
string strFire = System.Convert.ToString(Fire, 2);
string strRock = System.Convert.ToString(Rock , 2);
int combo1 = strFire | strRock ;
int combo2 = strRock | strFire ;
int combo3 = strFire | strFire ;
Hi, I’m trying to convert Fire and Rock integers into bits, so I can use bit operators on them. But I don’t know how. I’m still trying to find an answer on Google right now, but if anyone know the answer to this that would be very helpful
You don’t need to convert to string, you can use the operators directly on integers (or other integral types).
Reply to comment:
That’s not true. As your fire
is 1, fire|fire
will give 1.
Also if you are going to use bitwise operators it’s better to use powers of 2:
int Fire = 1; //0001
int Rock = 2; //0010
int Wind = 4; //0100
int Earth = 8; //1000
When you work with powers of 2 every OR operation on 2 items will give a distinct answer.
Fire|Earth
for instance will be 9.
while Earth|Earth
will be 8.
You should not need any string operations.
I read your other question (which is basically a duplicate now), if you want to check whether slot1 and slot2 have a combination of Rock and Wind you would just do:
int combination = slot1value | slot2value;
if (combination == 3)
//Fire + Rock
else if (combination == 5)
//Fire + Wind
else if (combination == 6)
//Wind + Rock
else if (combination == 9)
//Fire + Earth
else if (combination == 10)
//Rock + Earth
else if (combination == 12)
//Wind + Earth