Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
8-bit integer to bytes
#1
Hello...

I am attempting to use a Python3 library function that requires a binary parameter (bytes or bytearray).

When I submit a parameter such as b"7" the function operates properly.

But, I need it to accept an arbitrary 8-bit integer that I create by shifting up "one" bits.

I have tried several different conversion schemes, but cannot find one that works... Can you help?

73,
Garitron
Reply
#2
(1024).to_bytes(3, 'big')
https://docs.python.org/3/library/stdtypes.html#int.to_bytes
Craig "Ichabod" O'Brien - xenomind.com
I wish you happiness.
Recommended Tutorials: BBCode, functions, classes, text adventures
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  How to convert 4 bytes to an integer ? GiggsB 11 6,597 Jan-20-2022, 03:37 AM
Last Post: GiggsB
  Pack integer values as single bytes in a struct bhdschmidt 3 2,277 Jun-09-2020, 09:23 PM
Last Post: bhdschmidt
  replace bytes with other byte or bytes BigOldArt 1 10,531 Feb-02-2019, 11:00 PM
Last Post: snippsat

Forum Jump:

User Panel Messages

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