1

I know this should be easy, but I just can't get the syntax right for python.

My int is not converted correctly. This is the output of my 2 print statements. My output should be 9718 instead of 959918392.

bytearray(b'9718')
959918392

This is my conversion. I don't understand what am I doing wrong.

print(size)
print(int.from_bytes(size, byteorder='big'))
2
  • @apknusel That's definitely asking something else Commented Jan 25, 2021 at 4:15
  • yea, i made a mistake and assumed my bytearray was bytes[], but it acctly contained ascii Commented Jan 25, 2021 at 5:21

1 Answer 1

1

What you tried assumes the number is directly encoded as bytes. You actually want to parse it from ascii, which you can do like this:

int(b'9718'.decode('ascii'))
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.