>>> receptor_converter(4, "1111010010111111") (['1', '0', '1', '0', '1', '0', '1', '1', '1', '1', '1', '1'], True)
(size_par, data)
| 145 | |
| 146 | |
| 147 | def receptor_converter(size_par, data): |
| 148 | """ |
| 149 | >>> receptor_converter(4, "1111010010111111") |
| 150 | (['1', '0', '1', '0', '1', '0', '1', '1', '1', '1', '1', '1'], True) |
| 151 | """ |
| 152 | # data position template + parity |
| 153 | data_out_gab = [] |
| 154 | # Parity bit counter |
| 155 | qtd_bp = 0 |
| 156 | # Counter p data bit reading |
| 157 | cont_data = 0 |
| 158 | # list of parity received |
| 159 | parity_received = [] |
| 160 | data_output = [] |
| 161 | |
| 162 | for i, item in enumerate(data, 1): |
| 163 | # Performs a template of bit positions - who should be given, |
| 164 | # and who should be parity |
| 165 | if qtd_bp < size_par and (np.log(i) / np.log(2)).is_integer(): |
| 166 | data_out_gab.append("P") |
| 167 | qtd_bp = qtd_bp + 1 |
| 168 | else: |
| 169 | data_out_gab.append("D") |
| 170 | |
| 171 | # Sorts the data to the new output size |
| 172 | if data_out_gab[-1] == "D": |
| 173 | data_output.append(item) |
| 174 | else: |
| 175 | parity_received.append(item) |
| 176 | |
| 177 | # -----------calculates the parity with the data |
| 178 | data_out = [] |
| 179 | parity = [] |
| 180 | bin_pos = [bin(x)[2:] for x in range(1, size_par + len(data_output) + 1)] |
| 181 | |
| 182 | # sorted information data for the size of the output data |
| 183 | data_ord = [] |
| 184 | # Data position feedback + parity |
| 185 | data_out_gab = [] |
| 186 | # Parity bit counter |
| 187 | qtd_bp = 0 |
| 188 | # Counter p data bit reading |
| 189 | cont_data = 0 |
| 190 | |
| 191 | for x in range(1, size_par + len(data_output) + 1): |
| 192 | # Performs a template position of bits - who should be given, |
| 193 | # and who should be parity |
| 194 | if qtd_bp < size_par and (np.log(x) / np.log(2)).is_integer(): |
| 195 | data_out_gab.append("P") |
| 196 | qtd_bp = qtd_bp + 1 |
| 197 | else: |
| 198 | data_out_gab.append("D") |
| 199 | |
| 200 | # Sorts the data to the new output size |
| 201 | if data_out_gab[-1] == "D": |
| 202 | data_ord.append(data_output[cont_data]) |
| 203 | cont_data += 1 |
| 204 | else: |