Code:

'parse byte_array define OSC 8
bit_array var byte[4]
byte_array var byte[32]
arraywrite byte_array,[80,80,160,80,80,160,80,160,_
80,160,80,80,160,80,80,160,_
160,80,80,80,80,160,160,80,_
80,80,80,160,80,110,160,160]
n var byte
index var byte
trisa.1 =0
porta=2
pause 1000
serout2 porta.1 ,84 ,["ready",13]
n = 32
index = 0
find_bit:
if byte_array[index]>145 then '>725ìs
if byte_array[index]<180 then
bit_array.0[index]=0
index=index+1
if index<n then find_bit
endif
endif
if byte_array[index]<100 then '>725ìs
if byte_array[index]>75 then
bit_array.0[index]=1
index=index+1
if index<n then find_bit
endif
endif
serout2 porta.1 ,84 ,[bin8 bit_array[3], bin8 bit_array[2], _
bin8 bit_array[1], bin8 bit_array[0],13]
;my way
tolerance con 20
a_one con 90 ; mean value of a one bit
a_zero con 160 ; mean value of a zero bit
fail var bit
clear_result:
bit_array[0] = 0
bit_array[1] = 0
bit_array[2] = 0
bit_array[3] = 0
get_result:
n = 32
fail = 0
while n && (!fail)
n = n-1
index = byte_array[n] - a_one; bytewise abs shortcut
if index.7 then index = ~index+1; bytewise abs shortcut
if index <tolerance then ; (abs(byte_array[n] - a_one)) < tolerance
bit_array.0[n] = 1
else
index = byte_array[n] - a_zero ; bytewise abs shortcut
if index.7 then index = ~index+1 ; bytewise abs shortcut
if index then fail = 1 ;(abs(byte_array[n] - a_zero))>tolerance
endif
serout2 porta.1 ,84 ,["."]
wend
if fail then
serout2 porta.1 ,84 ,[13,"fail",13]
else
serout2 porta.1 ,84 ,[13,bin8 bit_array[3], bin8 bit_array[2], _
bin8 bit_array[1], bin8 bit_array[0],13]
endif

## Bookmarks