Bread_Editor/utils.py

33 lines
726 B
Python
Raw Normal View History

#!/usr/bin/python3
from pathlib import Path
class Utils:
def __init__(self, app):
self.app = app
self.home_path = str(Path.home())
def bstring_to_oz(self, data): # convert binary data to a string of ones and zeros (oz)
2024-11-19 18:04:01 +01:00
oz_bytes = []
for byte in data:
oz_bytes.append(format(byte, "08b"))
oz_string = " ".join(oz_bytes)
return oz_string
2024-11-19 18:32:52 +01:00
def oz_string_to_bstring(self, oz_string): # convert a string of zeroes and ones to a binary string
oz_bytes = oz_string.split()
bytes_int = []
for byte in oz_bytes:
bytes_int.append(int(byte, 2))
binary_string = bytes(bytes_int)
return binary_string