Exemple #1
0
    def from_filename(cls, filename, reverse_bits=False):
        real_bytes = open(filename, "rb").read()

        # from bytes -> list of binary-encoding strings [ "11010", "0111", ... ]
        bits_strs = [
            bin(byte)[2:] for byte in real_bytes
        ]

        # left-pad up to a full byte "11010" -> "00011010"
        byte_strs = [ util.pad_left(bits_str, 8) for bits_str in bits_strs ]

        # one big sequence of binary
        bin_str = "".join(byte_strs)

        return ByteStream(bin_str, reverse_bits=reverse_bits)
Exemple #2
0
def _int_to_padded_bin_str(int_value):
    return util.pad_left(bin(int_value)[2:], 7)
Exemple #3
0
def get_register_id(register_name):
    return util.pad_left(bin(Register[register_name])[2:], 4)
Exemple #4
0
    def hex_str(self, padded=False):
        if padded:
            return util.pad_left(hex(self.int_value)[2:], 2)

        return hex(self.int_value)[2:]
Exemple #5
0
    def bin_str(self, padded=False):
        if padded:
            return util.pad_left(bin(self.int_value)[2:], 7)

        return bin(self.int_value)[2:]