Convert binary to ASCII and vice versa

前端 未结 8 1145
余生分开走
余生分开走 2020-11-22 03:22

Using this code to take a string and convert it to binary:

bin(reduce(lambda x, y: 256*x+y, (ord(c) for c in \'hello\'), 0))

this outputs:<

8条回答
  •  醉话见心
    2020-11-22 04:03

    Are you looking for the code to do it or understanding the algorithm?

    Does this do what you need? Specifically a2b_uu and b2a_uu? There are LOTS of other options in there in case those aren't what you want.

    (NOTE: Not a Python guy but this seemed like an obvious answer)

提交回复
热议问题