Questions tagged [python-bytearray]

38 questions
1
vote
2 answers

How to fetch bytes from SQL Server Database and Convert to Image in Python

-- I'm loading test data into my SQL Server Database using python and was able to successfully take images and break them down into bytes and store them in the database, but when trying to fetch back the bytes and decode it to save it as a new…
benfsmith3
  • 21
  • 1
  • 4
1
vote
1 answer

Replacing byte in bytes array to fix encoding

I'm using ftfy to fix broken UTF-8 encoding that shows as CP1252 and convert it to UTF-8 cyrillic, but I've found that some letters can't be fixed. I have a string Ð'010СС199 that I convert to bytes and define pairs…
Rostislav Aleev
  • 351
  • 5
  • 19
1
vote
1 answer

How to optimize binary file manipulation?

here is my code: def decode(filename): with open(filename, "rb") as binary_file: # Read the whole file at once data = bytearray( binary_file.read()) for i in range(len(data)): data[i] = 0xff - data[i] with…
1
vote
0 answers

bytearray encoding, data misrepresented

I have a bytearray as follows: frame = bytearray() frame.append(0x6) frame.append(0x8) frame.append(0xf1) frame.append(0x1b) frame.append(0x3) frame.append(0x2) frame.append(0x1) frame.append(0x0) frame.append(0x0) frame.append(0x0) I am applying a…
arsenal88
  • 1,040
  • 2
  • 15
  • 32
1
vote
1 answer

What is causing the insertion of null-values into my byte array?

I am trying to use MSMQ to send a NMEA message to a C# sever. This NMEA message (string) is to be base64 encoded and then sent as a byte array. The problem I am running into is that in MSMQ my byte array is showing as: 03 00 00 00 00 00 00 00…
Infoblack
  • 51
  • 5
1
vote
2 answers

How can I append multiple copies of a value to a Python bytearray?

If I have a Python list (data) and two integers (i and count), I can easily append count copies of i to data: >>> data = [0] >>> i, count = 1, 4 >>> data += [i] * count >>> data [0, 1, 1, 1, 1] How can I do the same if data is a bytearray? Is it…
user200783
  • 13,722
  • 12
  • 69
  • 135
1
vote
1 answer

Convert a byte array to string

I have a bunch of numbers in a string array and I feel like they are bunch of bytes. I wonder how I can convert those numbers into an actual string representation. I guess I need to convert this string array to a byte array and later I can decode…
Tarik
  • 79,711
  • 83
  • 236
  • 349
0
votes
0 answers

Extracting and formatting the required numbers from a bytearray in python

question in python. I was trying to get data from a BLE device, The following bytearray was output. b'\x32\x33\x30\x38\x31\x37\x32\x32\x34\x35'#2308172245 b'\x44\x31\x32\x35\x43\x30\x39\x34\x35' # D125C0945 I want to extract and format it as…
mukuroji
  • 1
  • 1
0
votes
0 answers

how can I use some type of bytearray slice to modify the original bytearray in Python

I'm using Python's bytearrays to read from files using the readinto function from BufferedIOBase. This function requires a bytes-like object. I would like to have a header in the first few positions of this bytearray but the rest of the bytearray…
0
votes
1 answer

How to convert a cython char* filled with 0x00 to non-empty byte array

Here is a cython fonction: cdef struct my_struct_t: unsigned int a short b unsigned char[6] c cdef void f_my_struct_t(int buff_size, const unsigned char* buf, list output): cdef: my_struct_t *arr = buf …
Thibaut M.
  • 31
  • 5
0
votes
0 answers

Expected type to be one of bytes, bytearray but got str in Python

I'm having the small Python problem. I'm not used to this Python coding so my mistake might be silly one. I'm trying to call API using the Python requests module. Here I tried 2 methods but both showing different errors. So now, I'm getting any of…
Jay Bhajiyawala
  • 101
  • 1
  • 4
  • 11
0
votes
0 answers

Unable to convert bytes to hex

I have a serial device (loadcell) connected to pc which is constantly sending data in a fixed format. It has 2 stop bits (0x40 and 0x0b). I am trying to read until 1 stop bit so I can start reading the message from the start. The problem is the code…
bmw-m8
  • 1
  • 1
0
votes
1 answer

I want to execute lines of a text file as if they were part of my python script

I have a text file containing shellcode looking like this : buf += b"\x6d\x6b\x66\x69\x66\x6f\x20\x2f\x74\x6d\x70\x2f\x73" buf += b"\x35\x35\x20\x30\x3c\x2f\x74\x6d\x70\x2f\x73\x61\x6b" buf += b"\x6e\x20\x7c\x20\x2f\x62\x69\x6e\x2f\x73\x68\x20\x3e"…
0
votes
1 answer

Copying data into a buffer (byte array)

I am trying to copy a blob of data (some bytes) into a larger block at some position. I can do this easily enough in C, but now I am doing it in Python and I am curious as to what is the best/correct way to do this. The way I did it…
Xofo
  • 1,256
  • 4
  • 18
  • 33
0
votes
3 answers

String format byte array in Python 2.7

I am quite new to python and I am currently playing around with pyserial and what I am basically doing is sending simple commands via UART. A simple command that I have is: b'page 0\xff\xff\xff' which basically says to the hardware "Go on page with…