bytearray, type and format confusion
-
Hello, I could really use a hint here as to understand the type bytearray which I'm using for sending to a java socket on an rpi.
In REPL console I typed this:
data = bytearray() print(data) **bytearray(b'')** data.append(40000) print(data) **bytearray(b'@')** print(data, encoding='utf8') **bytearray(b'@')**What format is this? How come that the int 40000 is shown as '@' ?? It's not hexadecimal and it's not a byte (0-255), but obviously there's something I don't get..
-
@soren Add ``` alone on the lines before and after your code, or prefix them all with 4 spaces to have them formatted as code.
40000 % 256(or40000 & 255, i.e. keeping the 8 least significant bits) = 64, which is the code point for@.
Hello! It looks like you're interested in this conversation, but you don't have an account yet.
Getting fed up of having to scroll through the same posts each visit? When you register for an account, you'll always come back to exactly where you were before, and choose to be notified of new replies (either via email, or push notification). You'll also be able to save bookmarks and upvote posts to show your appreciation to other community members.
With your input, this post could be even better 💗
Register Login