Bonjour,
Au risque de passer pour un nul, je viens vous demander un peu d'aide.
Je dois créer une fonction en python qui est l'équivalent d'une fonction en C# (j'ai préféré poster dans le forum C#).
Voici la fonction C# telle quelle qui affiche un tableau de bytes :
En affichage de cette fonction, j'ai les chaînes 0x{0,4
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
22 /// <summary> /// Print the random bytes to the console. Format it such that each line is /// pre-pended with an index of the first byte, followed by bytes in hexadecimal /// format. /// </summary> /// <param name="bytesToWrite"></param> static void WriteBytes(byte[] bytesToWrite) { for (int i = 0; i < bytesToWrite.Length; i++) { if (i % ColumnsPerRow == 0) { Console.Write("0x{0,4:x4}: ", i); } Console.Write("0x{0,2:x2} ", bytesToWrite[i]); if (i % ColumnsPerRow == ColumnsPerRow - 1) { Console.WriteLine(); } } Console.WriteLine(); }4} qui sont interprétées, voici l'affichage :
Je n'arrive pas à comprendre l'interprétation du "0x{0,4
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 0x0000: 0x16 0x21 0xe2 0x32 0xd4 0x60 0x13 0x02 0x0008: 0x7d 0xa2 0x74 0x14 0x02 0xd3 0xe4 0xed 0x0010: 0x0e 0x31 0x04 0x8a 0x63 0x20 0x7d 0x28 0x0018: 0xf2 0x78 0x2e 0x85 0x9a 0x6a 0xfd 0xba 0x0020: 0xaf 0x0f 0x25 0x5b 0xb7 0x24 0x52 0x07 0x0028: 0xc0 0x14 0x41 0xaf 0x47 0xe2 0x70 0x7b4}" en "0x0008", "0x0010", "0x0018", "0x0020", "0x0028"
Et sur python, pour ceux que cela intéresse, j'ai codé ça :
Dont l'affichage n'est pas du tout interprété pareil (en fait qui n'est pas du tout interprété :
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 def WriteBytes(bytesToWrite): bytesToPrint = '' for i in range(0, len(bytesToWrite)): if i % ColumnsPerRow == 0: bytesToPrint += '0x{0,4:x4}' + ': ' + str(hex(i)) + ' ' bytesToPrint += '0x{0,2:x2} ' + str(hex(bytesToWrite[i])) + ' ' if i % ColumnsPerRow == ColumnsPerRow - 1: bytesToPrint += '\n' bytesToPrint += '\n' print bytesToPrint
J'aimerai donc comprendre pourquoi j'ai cette différence et si vous avez des pistes pour m'aider à trouver la solution en python je suis preneur.
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6 0x{0,4:x4}: 0x0 0x{0,2:x2} 0x94 0x{0,2:x2} 0x21 0x{0,2:x2} 0xcf 0x{0,2:x2} 0x8 0x{0,2:x2} 0x73 0x{0,2:x2} 0x77 0x{0,2:x2} 0x40 0x{0,2:x2} 0x9f 0x{0,4:x4}: 0x8 0x{0,2:x2} 0x23 0x{0,2:x2} 0x4f 0x{0,2:x2} 0x6f 0x{0,2:x2} 0xcf 0x{0,2:x2} 0xf5 0x{0,2:x2} 0xab 0x{0,2:x2} 0x76 0x{0,2:x2} 0x86 0x{0,4:x4}: 0x10 0x{0,2:x2} 0x8d 0x{0,2:x2} 0x95 0x{0,2:x2} 0xe7 0x{0,2:x2} 0xce 0x{0,2:x2} 0x31 0x{0,2:x2} 0x2a 0x{0,2:x2} 0x89 0x{0,2:x2} 0xdf 0x{0,4:x4}: 0x18 0x{0,2:x2} 0x88 0x{0,2:x2} 0xe 0x{0,2:x2} 0x9c 0x{0,2:x2} 0x79 0x{0,2:x2} 0xa 0x{0,2:x2} 0xbe 0x{0,2:x2} 0xd8 0x{0,2:x2} 0x3d 0x{0,4:x4}: 0x20 0x{0,2:x2} 0x63 0x{0,2:x2} 0x84 0x{0,2:x2} 0x8 0x{0,2:x2} 0x5d 0x{0,2:x2} 0x5b 0x{0,2:x2} 0x9d 0x{0,2:x2} 0x53 0x{0,2:x2} 0xa3 0x{0,4:x4}: 0x28 0x{0,2:x2} 0x2b 0x{0,2:x2} 0x79 0x{0,2:x2} 0x92 0x{0,2:x2} 0xc2 0x{0,2:x2} 0xa3 0x{0,2:x2} 0x98 0x{0,2:x2} 0xa1 0x{0,2:x2} 0x62
Merci d'avance,
Contrec
Partager