sync
This commit is contained in:
25
buzzer_tool/core/util.py
Normal file
25
buzzer_tool/core/util.py
Normal file
@@ -0,0 +1,25 @@
|
||||
def hex_to_bytearray(hex_string):
|
||||
"""
|
||||
Wandelt einen Hex-String (z.B. "deadbeef") in ein bytearray um.
|
||||
Entfernt vorher Leerzeichen und prüft auf Gültigkeit.
|
||||
"""
|
||||
try:
|
||||
# Whitespace entfernen (falls vorhanden)
|
||||
clean_hex = hex_string.strip().replace(" ", "")
|
||||
|
||||
# Konvertierung
|
||||
return bytearray.fromhex(clean_hex)
|
||||
|
||||
except ValueError as e:
|
||||
print(f"Fehler bei der Konvertierung: {e}")
|
||||
return None
|
||||
|
||||
def string_to_hexstring(text):
|
||||
"""
|
||||
Wandelt einen String in einen UTF-8-kodierten Hex-String um.
|
||||
"""
|
||||
# 1. String zu UTF-8 Bytes
|
||||
utf8_bytes = text.encode('utf-8')
|
||||
|
||||
# 2. Bytes zu Hex-String
|
||||
return utf8_bytes.hex()
|
||||
Reference in New Issue
Block a user