bonjour
je suis entrain de m'anipuler des int; j'arrive a effectuer des Xor et autres fonctions logiques tels que les decalages !!
j'aimerais savoir comment effectuer un decalage cyclique ?
mci
Version imprimable
bonjour
je suis entrain de m'anipuler des int; j'arrive a effectuer des Xor et autres fonctions logiques tels que les decalages !!
j'aimerais savoir comment effectuer un decalage cyclique ?
mci
non, mais vous pouvez vous inspirer de l'implémentation integer pour faire la votre en short et en long
Code:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34 757 public static int rotateLeft(int i, int distance) { 758 if (distance == 0) { 759 return i; 760 } 761 /* 762 * According to JLS3, 15.19, the right operand of a shift is always 763 * implicitly masked with 0x1F, which the negation of 'distance' is 764 * taking advantage of. 765 */ 766 return ((i << distance) | (i >>> (-distance))); 767 } 768 769 /** 770 * Rotates the bits of the specified integer to the right by the specified 771 * number of bits. 772 * 773 * @param i 774 * the integer value to rotate right. 775 * @param distance 776 * the number of bits to rotate. 777 * @return the rotated value. 778 * @since 1.5 779 */ 780 public static int rotateRight(int i, int distance) { 781 if (distance == 0) { 782 return i; 783 } 784 /* 785 * According to JLS3, 15.19, the right operand of a shift is always 786 * implicitly masked with 0x1F, which the negation of 'distance' is 787 * taking advantage of. 788 */ 789 return ((i >>> distance) | (i << (-distance))); 790 }
La méthode n'est pas disponible dans la classe Short. Tu dois faire ta propre méthode.
Le cast ne donnera pas le bon résultat car la rotation se fait sur la totalité des bits du int mais le short a moins de bit.
EDIT : trop lent :aie: