SA-MP Forums Archive
<<= 1 Mean - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: <<= 1 Mean (/showthread.php?tid=664652)



<<= 1 Mean - cengiz6155 - 06.03.2019

enum e_PLAYER_FLAGS (<<= 1)

What does it mean?


Re: <<= 1 Mean - Rafaly - 06.03.2019

PLAYER_IS_LOGGED_IN


Re: <<= 1 Mean - cengiz6155 - 06.03.2019

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


Re: <<= 1 Mean - cengiz6155 - 06.03.2019

What does operator mean? <<= 1


Re: <<= 1 Mean - NaS - 06.03.2019

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.


Re: <<= 1 Mean - cengiz6155 - 06.03.2019

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?


Re: <<= 1 Mean - IllidanS4 - 06.03.2019

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).


Re: <<= 1 Mean - cengiz6155 - 06.03.2019

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


Re: <<= 1 Mean - v1k1nG - 06.03.2019

One of the best threads ever!