0

I have the following bytearray

bytearray(b'S\x00t\x00a\x00n\x00d\x00a\x00r\x00d\x00F\x00i\x00r\x00m\x00a\x00t\x00a\x00.\x00i\x00n\x00o\x00') 

It should spell out StandardFirmata.ino however, I can't figure out how to decode it.

Here is what I have tried:

print(str(board.sysex_list)) #Appears to just return a string that looks identical print(board.sysex_list.decode()) # Returns just S 

Is there a simple way to do this?

2 Answers 2

7

Wrong encoding.

3>> bytearray(b'S\x00t\x00a\x00n\x00d\x00a\x00r\x00d\x00F\x00i\x00r\x00m\x00a\x00t\x00a\x00.\x00i\x00n\x00o\x00').decode('utf-16le') 'StandardFirmata.ino' 

But that's not ASCII.

Sign up to request clarification or add additional context in comments.

2 Comments

Any good resources on this mysterious bytearray object? The documentation did not help much. To me it just looks like a string of bytes that returns ints when indexed....
That's because that's what it is: a sequence of bytes. If you want to turn it into text then you need to decode it using the appropriate encoding.
1

The issue was that I was not specifying a decoding. All I had to do was change decode to decode('utf-16-le')

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.