Skip to content

Instantly share code, notes, and snippets.

@nvasilakis
Last active August 29, 2015 14:01
Show Gist options
  • Select an option

  • Save nvasilakis/aab24aeb19c9c9852ac4 to your computer and use it in GitHub Desktop.

Select an option

Save nvasilakis/aab24aeb19c9c9852ac4 to your computer and use it in GitHub Desktop.
Encoding in Python
# + http://stackoverflow.com/questions/11826054/valueerror-invalid-literal-for-int-with-base-16-x0e-xa3-python
encodeByte(3, 42)
#-84
n = '\x03'
n
#'\x03'
len(n)
#1
int(n)
#Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
#ValueError: invalid literal for int() with base 10: '\x03'
import struct
struct.unpack('B',n)
#(3,)
encodeByte(b, 42)
#Traceback (most recent call last):
# File "<stdin>", line 1, in <module>
# File "<stdin>", line 2, in encodeByte
#TypeError: unsupported operand type(s) for >>: 'str' and 'int'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment