Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import math
- mess=input()
- cm=''
- for i in mess:
- arr = list("{0:b}".format(ord(i)).zfill(7))
- print("Debug messages...", arr, file=sys.stderr)
- j=0
- count=1
- cm=''
- new=''
- while j < len(arr)-1:
- if j == 0: # get first series item
- currentSeries = arr[0]
- if arr[j] == arr[j+1]: # if current item is equal to the next count and move to along to next item in loop
- count+=1
- if arr[j] != arr[j+1] or j == len(arr)-2: # update the new string with the code, change the series for next binary 0 or 1
- if currentSeries == '1':
- new+='0 ' # code for 1
- currentSeries='0' #end of series so switch binary digit
- else:
- new+='00 ' # code for 0
- currentSeries='1' #end of series so switch binary digit
- new+='0'*count # add the amount of 0's according to the count + plus 1 for being the last/current item
- count=1 # reset the counter
- if j != len(arr)-2: # if not the end of array add a space, we do this as we don't want space at end of string
- new+=' '
- j+=1
- #End of while
- print(new)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement