Mabignix
Mabignix

Reputation: 11

Python big values in one byte array

Can someone help me how to put these int values in one byte array? I would like to have one array, which I can send over a socket.

lat=int(4065538)
lon=int(1446611)
velo=int(33)

I can put every value to one byte stream with

lat = lat.to_bytes(3, 'big')
lon = lon.to_bytes(3, 'big')
velo = velo.to_bytes(2, 'big')

but I don't know how to bring them to one. Thank you!

Upvotes: 0

Views: 132

Answers (1)

user16036731
user16036731

Reputation: 56

First create an empty bytearray, then concat to it

data = bytearray()

data += lat.to_bytes(3, 'big')
data += lon.to_bytes(3, 'big')
data += velo.to_bytes(2, 'big')

Upvotes: 1

Related Questions