Untitled
unknown
plain_text
a year ago
829 B
21
Indexable
#Experiment 2
from array import *
my_array = array('i', [0, 1, 1, 1, 0,1, 1, 1, 0])
def bitstuff(array):
i = 0
count = 0
while i < len(array):
if array[i] == 1:
count += 1
else:
count = 0
if count == 5:
array.insert(i + 1, 0)
i += 1
def destuff(array):
i = 0
count = 0
while i < len(array):
if array[i] == 1:
count += 1
else:
count = 0
if count == 5:
if i + 1 < len(array) and array[i + 1] == 0:
array.pop(i + 1)
count = 0
i += 1
bitstuff(my_array)
print("After bit-stuffing:", my_array.tolist())
destuff(my_array)
print("After de-stuffing:", my_array.tolist())
Editor is loading...
Leave a Comment