Python Forum
How to understand the byte notation in python3
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
How to understand the byte notation in python3
#2
It's not a single byte, it's a bytes object which can hold several bytes. When printed, if the byte is in the ASCII range, it shows the ASCII character. If the byte is not in ASCII, it shows the value with 2 hexadecimal digits. Your object has 4 bytes inside. As an example, to break down your string into the component bytes in character, decimal, and hex form:

>>> for byte in b'\x12AY5':
...  print(f"{repr(chr(byte)):>6s} - {byte} - {byte:x}")
...
'\x12' - 18 - 12
   'A' - 65 - 41
   'Y' - 89 - 59
   '5' - 53 - 35
As it's not a single byte, you have a choice of what order if you want to assemble it into a single 32-bit decimal.


12 41 59 35 => 306272565
35 59 41 12 => 895041810
blackknite likes this post
Reply


Messages In This Thread
RE: How to understand the byte notation in python3 - by bowlofred - Feb-23-2021, 08:31 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Forcing matplotlib to NOT use scientific notation when graphing sawtooth500 4 451 Mar-25-2024, 03:00 AM
Last Post: sawtooth500
  ''.join and start:stop:step notation for lists ringgeest11 2 2,476 Jun-24-2023, 06:09 AM
Last Post: ferdnyc
  issue with converting a scientific notation to standard notation thomaswfirth 4 1,429 Jun-06-2023, 06:06 PM
Last Post: rajeshgk
  notation MCL169 8 1,550 Apr-14-2023, 12:06 PM
Last Post: MCL169
  Issue in writing sql data into csv for decimal value to scientific notation mg24 8 3,147 Dec-06-2022, 11:09 AM
Last Post: mg24
  Graphics Formatting - X-axis Notation and Annotations - Matplotlib silviover_junior 0 1,825 Mar-17-2021, 01:19 PM
Last Post: silviover_junior
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 11,729 Sep-18-2020, 10:10 PM
Last Post: tienttt
  Simple question concerning python dot notation. miner_tom 1 1,938 Mar-24-2020, 05:20 PM
Last Post: buran
  'utf-8' codec can't decode byte 0xda in position 184: invalid continuation byte karkas 8 31,836 Feb-08-2020, 06:58 PM
Last Post: karkas
  Gnuradio python3 is not compatible python3 xmlrpc library How Can I Fix İt ? muratoznnnn 3 4,988 Nov-07-2019, 05:47 PM
Last Post: DeaD_EyE

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020