Quote:
Originally Posted by cocoemre
Yes, it looks good i guess i will solve it when i go home.
Can someone give me this codes;
1UL >> 62, ???????
1UL >> 63 = ???????
1UL >> 64 = ???????
1UL >> 65 = ???????
1UL >> 66 = ???????
1UL >> 67 = ???????
|
So, let's get started with a small correction: these examples are backwards. You should be doing left bit shifts, not right. With that out of the way, these are integer literals for a bit shift from unsigned long 1. In other words, the C# compiler understands how to resolve this operation for you as part of the language. If you want to learn how to resolve this yourself by hand, then you'll need to understand binary. In very basic sense,
Code:
0 decimal = 0 binary
1 decimal = 1 binary
2 decimal = 10 binary
3 decimal = 11 binary
4 decimal = 100 binary
etc.
Binary is just a base 2 number system (0 and 1). For reference, decimal is a base 10 system (0 through 9).
This can be represented by the number of bits a 1 can be shifted over by. So for example,
Code:
1 << 0 = 1 binary = 1 decimal
1 << 1 = 10 binary = 2 decimal
1 << 2 = 100 binary = 4 decimal
1 << 3 = 1000 binary = 8 decimal
A really good way to increment this quickly by hand in decimal is to remember your powers of 2. (2 ^ 4) in decimal is the same as 1 << 4. Simply put, you can do this because binary places are powers of 2 in decimal.
You don't have to do any of this by hand though. If you start up a Calculator on Windows or Mac, there's a Programmer mode you can set it in from the menu. Then, you'll have access to the bit shift operators. It'll show you that number in binary, decimal, hexadecimal, and octal. You don't have to convert any of these shifts into decimals though. As I said, the language understands these operations as literals, so you can just place them in your source instead of using those weird decimal numbers that make little sense.
Edit: Here's a full tutorial I found on bit flags (which is what status effects are):
But as a summary, you can apply multiple status effects using bitwise operations and bit shifting. Each 1 in the bitmap indicates that the status effect is enabled. So for example, you can be both poisoned (1 << 1 or 10 in binary) and blue name flashing (1 << 0 or 1 in binary), which is 11 in binary. You combine them using bitwise OR operations. More info is in that tutorial I linked you to.