Python Forum
Thread Rating:
  • 1 Vote(s) - 2 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Byte-Array
#4
I guess there is no one right way how you can solve this task.

You can work with binascii.hexlify
from binascii import hexlify


ba = bytearray(b'\xd0\x13t')
hexstr = hexlify(ba).decode() # hexlify returns bytes
print(hexstr)
Another method could be str-formatting:
ba = bytearray(b'\xd0\x13t')
hexstr = ''.join(format(integer, 'x') for integer in ba) 
print(hexstr)
For Python 3.6 fans with format string interpolation:
ba = bytearray(b'\xd0\x13t')
hexstr = ''.join(f'{integer:x}' for integer in ba) 
print(hexstr)
Almost dead, but too lazy to die: https://sourceserver.info
All humans together. We don't need politicians!
Reply


Messages In This Thread
Byte-Array - by okmog - Jun-13-2018, 11:58 AM
RE: Byte-Array - by volcano63 - Jun-13-2018, 01:49 PM
RE: Byte-Array - by ljmetzger - Jun-13-2018, 02:01 PM
RE: Byte-Array - by DeaD_EyE - Jun-13-2018, 03:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  extract only text strip byte array Pir8Radio 7 2,986 Nov-29-2022, 10:24 PM
Last Post: Pir8Radio
  'utf-8' codec can't decode byte 0xe2 in position 122031: invalid continuation byte tienttt 12 11,592 Sep-18-2020, 10:10 PM
Last Post: tienttt
  convert array of numbers to byte array adetheheat 3 2,816 Aug-13-2020, 05:09 PM
Last Post: bowlofred
  Convert even byte array to odd medatib531 1 2,224 Mar-17-2020, 02:48 AM
Last Post: scidam
  'utf-8' codec can't decode byte 0xda in position 184: invalid continuation byte karkas 8 31,721 Feb-08-2020, 06:58 PM
Last Post: karkas
  Byte array is sorted when sending via USB daviddlc68 1 2,838 Aug-16-2019, 10:11 AM
Last Post: wavic
  Reading data from serial port as byte array vlad93 1 12,086 May-18-2019, 05:26 AM
Last Post: heiner55
  Read Byte Array from Zigbee coordinator using python jenkins43 3 3,894 Mar-26-2019, 03:03 PM
Last Post: micseydel
  Not able to Read byte Array From Wireless Coordinator jenkins43 0 1,904 Mar-18-2019, 07:05 AM
Last Post: jenkins43
  4 byte hex byte swap from binary file medievil 7 22,127 May-08-2018, 08:16 AM
Last Post: killerrex

Forum Jump:

User Panel Messages

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