MOD to Pawn
#1

Hello!
I want to check if a number is even or uneven.
For those who don't understand: 1 - uneven, 2 - even, 3 - uneven ... etc.

In c++ I am doing this at school by using this:
PHP код:
if(x%2
PHP код:
if(x%== 0
how can I do this in PAWN?
Reply
#2

Do they teach you how to use the search function at school aswell? If not, I think it'd be great if you got that class, because you apparently need it sir.
https://sampforum.blast.hk/showthread.php?tid=70747
Reply
#3

I searched only for MOD samp on ******. thank you!
Reply
#4

I searched on samp wiki and this is the only way i found but the script will look a mess xd:
https://sampwiki.blast.hk/wiki/Control_Structures#else
With ELSE & IF.
Reply
#5

Just use that instead of MOD
pawn Код:
#define IsOdd(%0) (%0 & 1)
Reply
#6

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just use that instead of MOD
pawn Код:
#define IsOdd(%0) (%0 & 1)
This, with this for even:
pawn Код:
#define IsEven(%0) (!IsOdd(%0))
Quote:
Originally Posted by SumX
Посмотреть сообщение
PHP код:
if(x%2
PHP код:
if(x%== 0
Those should work too, but binary (thus, the binary AND above) is better.
Reply
#7

Quote:
Originally Posted by Nero_3D
Посмотреть сообщение
Just use that instead of MOD
pawn Код:
#define IsOdd(%0) (%0 & 1)
FIY this checks if the last bit is set, so if the binary numbers contains a 1. A clever method, dont think the compiler optimizes this by itself.
Reply


Forum Jump:


Users browsing this thread: 3 Guest(s)