I have a list of binary number and the bit need to be flipped from 0 to 1 or 1 to 0 for the prime index only. The list of binary number is actually near to 100 bit length. I have a code for example 8 bit long but it does not show the expected output:
def prime_index (input):
p = list(input)
s = ""
# Loop to check if
# index prime or not
for i in range (2, len(p) + 1):
if isPrime(i):
s = s + input[i-1]
flip = {'0': '1', '1':'0'}
flip=(flip[input[i]])
print (flip)
print (s)
input="11111111"
prime_index(input)
I get the output like this:
0
0
0
0
1111
The result should show like this, where the bit flipped for the index of [2, 3, 5, 7]:
output:11001010
Hopefully someone may help me. Thank you.