0

I am working on sending bytes to a USB device from a Python application. An example payload looks as follows:

a = bytearray(b'\x00\xb4nn\x00\x00\x00\x00\x00')

What I am curious about is the nn part, following \xb4nn - the string, in the current form, cannot be converted to either UTF-8 or ASCII. In some payload cases, that string can also be \xb4n, which seems like an odd way to present HEX information.

What is nn in a byte string?

4
  • It doesn't sound like this bytestring actually represents text, so trying to interpret it as UTF-8 or ASCII doesn't make sense. Commented Jun 28, 2020 at 0:23
  • Makes sense. Let's assume that it's not representing text then - what can I do to understand what that nn part represents? Commented Jun 28, 2020 at 0:25
  • 1
    Two \x6e bytes. Bytes that correspond to regular ascii characters are displayed as those characters in a bytestring repr. There's probably a dupe around here somewhere. Commented Jun 28, 2020 at 0:38
  • nn means exactly nn - two chars n. If you need its hex code - hex(ord('n')) Commented Jun 28, 2020 at 3:05

1 Answer 1

1

Printable ASCII byte values are displayed as ASCII. It is only a display convention, similar to the leading b indicating a byte string. The byte values are still the same. For example, ASCII n is the byte value 0x6E, and if you create a byte string with these values, it will be displayed as:

>>> b'\x6e\x6e'
b'nn'

Also:

>>> b'\x6e\x6e' == b'nn'
True
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.