Guest User

Untitled

a guest
Apr 22nd, 2018
72
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.36 KB | None | 0 0
  1. def utf2ucs(utf):
  2. if utf & 0x80:
  3. # multibyte
  4. buf = []
  5. while not(utf & 0x40):
  6. buf.append(utf & 0x3f)
  7. utf >>= 8
  8. buf.append(utf & (0x3f >> len(buf)))
  9.  
  10. ucs = 0
  11. while buf != []:
  12. ucs <<= 6
  13. ucs += buf.pop()
  14. else:
  15. # ascii
  16. ucs = utf
  17.  
  18. return unichr(ucs)
Add Comment
Please, Sign In to add comment