Bonjour à tous les utilisateurs de Flowcode,
j'ai une question qui va surement vous paraitre simple. Comment savoir si un chiffre est pair ou impair.
Je dois tester si un nombre est 1,3,5,7,11,13,15,17,19 donc impair. Et si 2,4,6,8,10,12,14,16,18 est pair.
En fonction du résultat, j'envoie sur deux conditions : c'est pair alors x=1, c'est impair x=0
Merci d'avance pour votre aide précieuse.
Cordialement
Lecalou60
Test si nombre pair ou impair
Moderator: Benj
-
- Posts: 80
- Joined: Fri Jul 20, 2012 8:55 am
- Location: Chambly (France)
- Been thanked: 4 times
- Contact:
- Benj
- Matrix Staff
- Posts: 15312
- Joined: Mon Oct 16, 2006 10:48 am
- Location: Matrix TS Ltd
- Has thanked: 4803 times
- Been thanked: 4314 times
- Contact:
Re: Test si nombre pair ou impair
Bonjour,
Cette réponse est assez simple à réaliser à l'aide d'une opération ET binaire et en testant le bit le moins significatif de la variable / constante.
x = nombre & 1
x = 0 - nombre est pair
x = 1 - nombre est impair
Hello,
Yes this is fairly simple to achieve using a binary AND operation and testing the least significant bit of the variable / constant.
x = number & 1
x = 0 - number = even
x = 1 - number = odd
Cette réponse est assez simple à réaliser à l'aide d'une opération ET binaire et en testant le bit le moins significatif de la variable / constante.
x = nombre & 1
x = 0 - nombre est pair
x = 1 - nombre est impair
Hello,
Yes this is fairly simple to achieve using a binary AND operation and testing the least significant bit of the variable / constant.
x = number & 1
x = 0 - number = even
x = 1 - number = odd
Regards Ben Rowland - MatrixTSL
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel
Flowcode Product Page - Flowcode Help Wiki - Flowcode Examples - Flowcode Blog - Flowcode Course - My YouTube Channel