Bonjour,

J'ai un nombre (int) compris entre 0 et 16 777 215 (0xFFFFFF).

Je voudrais le convertir en chaine de caractère hexa fixe (6 caractères) en inversant les octets.

Ex : 12346 (= 0x303A)
=> "00303A" (transformation en string sous forme hexa)
=> resultat : "3A3000" (inversion des octets)

Comment feriez-vous ?

voici mon coade actuel :
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
 
	private static String convInt(Integer val){
		String valStr, valStr2 = new String();
 
		if ((0 <= val) && (val <= 0xFFFFFF)){
			valStr = Integer.toHexString(val);
 
			for (char i=0; i <= (6 - valStr.length()); i++){
				valStr = "0" + valStr;
			}
 
			for (char i=0; i < 3; i++){
				valStr2 += valStr.substring(6-(i*2)-2, 6-(i*2));
			}
		} else {
			valStr2 = "------";				
		}
 
		System.out.println(valStr2);
		return valStr2;
	}