v.0.2.1 is_letter_assigned_right
This commit is contained in:
@@ -1,11 +1,63 @@
|
||||
import time
|
||||
|
||||
|
||||
def show_byte_matrix(char, matrix):
|
||||
print(f'byte_matrix: char({char})')
|
||||
matrix_str = [f'0x{byte:02X}' for byte in matrix]
|
||||
[print(f'{matrix_str[idx]} {number_to_bitarray_msb(byte)}') for idx, byte in enumerate(matrix)]
|
||||
|
||||
|
||||
def number_to_bitarray_msb(number):
|
||||
"""Convert 8-bit number to bit array (MSB first)"""
|
||||
return [(number >> i) & 1 for i in range(7, -1, -1)]
|
||||
|
||||
|
||||
def is_letter_assigned_right(char, letter) -> bool:
|
||||
"""Prüfe ob das Zeichen auch komplett nach rechts gezogen ist
|
||||
|
||||
Args:
|
||||
letter (_type_): Array[0..nBytes]
|
||||
|
||||
Returns:
|
||||
bool: _description_
|
||||
"""
|
||||
|
||||
def isLetterRight(letter):
|
||||
def isByteRight(byte):
|
||||
return True if 1 & byte == 1 else False
|
||||
|
||||
for byte in letter:
|
||||
if isByteRight(byte):
|
||||
return True
|
||||
|
||||
return False
|
||||
|
||||
def shiftLetterRight(letter):
|
||||
def shift(letter):
|
||||
return [byte >> 1 for byte in letter]
|
||||
|
||||
shifted = letter
|
||||
for i in range(8): # max 1 Bit's
|
||||
shifted = shift(shifted)
|
||||
if isLetterRight(shifted):
|
||||
break
|
||||
|
||||
return shifted
|
||||
|
||||
if isLetterRight(letter):
|
||||
return True
|
||||
|
||||
# letter is not right shifted
|
||||
shifted = shiftLetterRight(letter)
|
||||
|
||||
print('origin:')
|
||||
show_byte_matrix(char, letter)
|
||||
print('shifted')
|
||||
show_byte_matrix(char, shifted)
|
||||
|
||||
return False
|
||||
|
||||
|
||||
def get_datetime_string(format='full'):
|
||||
"""
|
||||
Return date/time as string with different formats
|
||||
|
||||
Reference in New Issue
Block a user