From a3663b7b3bdc092fb0667ea6c16b8e9a6cf4cf73 Mon Sep 17 00:00:00 2001 From: Kévin Le Gouguec Date: Thu, 21 Mar 2019 16:37:26 +0100 Subject: [implem-python] Utilisation des divisions entières // MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Plutôt que int() ; moins de bruit. … Au passage, simplification (j'espère) de ArrayToBlockbytesMatrix() : - pas besoin d'initialiser la matrice à zéro ; suffit d'ajouter les octets et les blocs comme ils viennent, - AFAICT, int((length + (BLOCK_BYTES - (length % BLOCK_BYTES))) / BLOCK_BYTES) quand length % BLOCK_BYTES > 0, c'est juste une façon compliquée d'écrire int(length/BLOCK_BYTES) + 1 --- python/lilliput_ae_1.py | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) (limited to 'python/lilliput_ae_1.py') diff --git a/python/lilliput_ae_1.py b/python/lilliput_ae_1.py index 9aad3a6..0bc4236 100644 --- a/python/lilliput_ae_1.py +++ b/python/lilliput_ae_1.py @@ -31,13 +31,14 @@ def LowPart(array, number_bits): lower_part = shifted & mask - will_padd = 0 + will_pad = 0 if number_bits % 8 != 0: - will_padd = 1 + will_pad = 1 - lower_part_byte = [0 for byte in range(0, int(number_bits / 8) + will_padd)] - for byte in range(0, int(number_bits / 8) + will_padd): - lower_part_byte[byte] = lower_part & 0xff + lower_part_byte = [] + nb_bytes = number_bits//8 + will_pad + for byte in range(nb_bytes): + lower_part_byte.append(lower_part & 0xff) lower_part = lower_part >> 8 return lower_part_byte -- cgit v1.2.3