<<= 1 Mean
#1

enum e_PLAYER_FLAGS (<<= 1)

What does it mean?
Reply
#2

PLAYER_IS_LOGGED_IN
Reply
#3

Quote:
Originally Posted by Rafaly
Посмотреть сообщение
PLAYER_IS_LOGGED_IN
What
Reply
#4

What does operator mean? <<= 1
Reply
#5

It's a bit shift.

If you have a binary number, eg 0b0101 it will become 0b1010 (all bits are shifted 1 position to the left).

What it does in this case is shift every entries' value 1 to the left per item in the enumerator.

The first one will be 1 (0b1), the second will be 0b10, the third 0b100, etc.
It lets you make a list of flags without having to manually assign a value to each one, it will build the order automatically.
Reply
#6

Quote:
Originally Posted by NaS
Посмотреть сообщение
It's a bit shift.

If you have a binary number, eg 0b0101 it will become 0b1010 (all bits are shifted 1 position to the left).
What does it do in enum?
Reply
#7

It is a way of specifying how the consequent values in an enum get assigned. These two enums are equivalent:
pawn Код:
enum E (<<= 1)
{
    E1 = 1,
    E2,
    E3,
    E4
}
pawn Код:
enum E
{
    E1 = 1, //0b1
    E2 = 1 << 1, //0b10
    E3 = (1 << 1) << 1, //0b100
    E4 = ((1 << 1) << 1) << 1 //0b1000
}
The parentheses can contain bit shift, addition, and multiplication assignment operations. The default operation is (+= 1).
Reply
#8

Quote:
Originally Posted by IllidanS4
Посмотреть сообщение
It is a way of specifying how the consequent values in an enum get assigned. These two enums are equivalent:
pawn Код:
enum E (<<= 1)
{
    E1 = 1,
    E2,
    E3,
    E4
}
pawn Код:
enum E
{
    E1 = 1, //0b1
    E2 = 1 << 1, //0b10
    E3 = (1 << 1) << 1, //0b100
    E4 = ((1 << 1) << 1) << 1 //0b1000
}
The parentheses can contain bit shift, addition, and multiplication assignment operations. The default operation is (+= 1).
Thxxx
Reply
#9

One of the best threads ever!
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)