7,821 questions
-3
votes
0
answers
57
views
Why do machines use kibibytes instead of kilobytes? Do they? [closed]
I'm kind of a beginner in all this CS stuff but let me try to explain what I'm asking.
A bit is basically an "on" or "off" switch which just stores the value of either "true&...
Advice
0
votes
4
replies
53
views
How to write bytes as a b' string to a file?
from PIL import Image
img = Image.open('some/file.png')
img = img.convert(mode='1')
imgbytes = img.tobytes()
with open('filepath', 'w') as file_out:
file_out.write(imgbytes)
I would like to write the ...
0
votes
1
answer
59
views
Error: "'utf-8' codec can't decode byte 0xd6 in position 4: invalid continuation byte" when trying to open .wav file
I am receiving my ".wav" file in a django view as an "InMemoryUploadedFile" then converting it to bytes:
views.py
import functions.bytes_to_wav_wave
if voice_value:
...
1
vote
1
answer
138
views
Why can't I return type byte in lambda expression in Arrays.setAll
I'm trying to implement a lambda function (for educational purposes) to initiate an array to append to the front of potentially encrypted data to save information like salt and initiation vector, ...
0
votes
2
answers
63
views
Calculate byte positions to split ndjson files into chunks
Below is the code extracted from this repo:
import os.path, io
filename = ""
n_chunks = 12 # Number of processes to use -- will split the file up into this many pieces
def ...
0
votes
1
answer
176
views
Split payload data from sensor into separate bytes length
Please I'm having an issue where I need to split a payload coming from an energy meter into chunks of 5-bytes each that represent different values of line parameters. The payload length is 35 bytes as ...
4
votes
2
answers
177
views
How can I convert a char into an int within the range of 0 and 255 in C++
I am trying to make my own file compressor and some of the chars in the file that I am trying to compress are '�'.
I tried:
#include <iostream>
int main(){
std :: cout << (int)'�';
...
0
votes
2
answers
130
views
How to reverse the bytes of a number in Excel?
In an excel cell, I have a large number represented as a string, lets say 12345689994765411.
I am looking for a way to reverse the bytes inside that number to get the decimal representation of that ...
0
votes
1
answer
62
views
RabbitMQ received bytes are invalid
I've a rabbitMQ implementation (C# with RabbitMQ.Client 7.1.12 nuget) where we send a short json to a queue. But when the receiver gets the queue item sometimes (approximately 1 on 5) the byte array ...
1
vote
2
answers
139
views
How can i convert a negative binary number to sbyte(c#)
I am messing around with c#, and i noticed something. If i were to instantiate an sbyte
with 8 bits, such as 0b_1111_1111 (-1), it throws an error, but if i were to first make a byte with it, and then ...
-2
votes
2
answers
133
views
Add a byte after every n-th byte in a bytearray
I want to add a byte after every third byte in a byte array.
# This is an example of where the bytes would be added
b'\xF2\xA1\x23{ADD}\xFF\x00\x05{ADD}\xE2\x20\x05{ADD}...'
Usually, I have a byte ...
0
votes
1
answer
43
views
How to serialize protobuf message into a pre-allocated byte array with offset in c#? (Protobuf 3.32.0.0)
The methods AI showed me are not working. However, one method mentioned by AI seems to be usable, but it is private:
private CodedOutputStream(byte[] buffer, int offset, int length)
So, how can I ...
1
vote
2
answers
147
views
How to switch between different BYTE Arrays after user input?
I would like to switch between different BYTE Arrays after user input. I need to apply the same processing to different arrays depending on user input, but I would like to avoid repeating the code. ...
-5
votes
1
answer
80
views
Bytes type is required [closed]
I am getting the error message
data_new.write(binary_data[j])
TypeError: a bytes-like object is required, not 'int'
although binary_data should be bytes-like.
data_new = open(Datei_neu, "wb"...
0
votes
0
answers
64
views
What is the diffrence between a byte string and a normal string in python? [duplicate]
I have gone through dozens of articles, and this StackOverflow thread but I'm still as clueless as ever. The main points I have read everywhere and why I don't understand them are:
The main points I ...
0
votes
1
answer
121
views
C# String to literal bytes [duplicate]
I would like to extract text from a textbox and use it as a hexadecimal:
When someone types in "80" into the textbox, I want to be converted from string to hex "0x80", not "...
-3
votes
1
answer
73
views
I can't find the error in this code. It is x86 assembly
Input: unsigned char vet[] = { 0xBC,0xFF,0x01 };unsigned short int len = 18;
Output: short int minLung;short int maxLung;
Given a sequence of bits, determine the minimum and maximum length of ...
0
votes
0
answers
45
views
Comparing strings received as bytes
I'm running a python script that receives data over a TCP connection. This connection can send multiple messages that consists of multiple variables which have multiple data types. When a string is ...
4
votes
1
answer
129
views
Adding text file attachments to Keepass with pykeepass in python
I am trying to create and save KeePass entries using pykeepass and saving a .txt file as an attachment. However I get a type-error:
Traceback (most recent call last):
File "c:\Users\...
0
votes
0
answers
48
views
How to write a string containing binary representation of data to file? [duplicate]
I am trying to write a binary string as binary data to file but my function seems to be having a problem with the int conversion. I am reading a text file and manipulating it which gives me a string ...
0
votes
1
answer
103
views
Converting two property values from byte to string in a result array in powershell
I see a lot of questions and answer regarding converting a byte array into string however my case is quite different and I cannot for the life of me find a way to do what I need.
I generate a result ...
0
votes
0
answers
38
views
How to serialize mpf object to raw binary bytes or bytearray in python mpmath
I'm working on a python program that uses mpmath to implement the Chunovsky algorithm for computing pi. I want to make my program log its progress to a file on regular intervals, so that I can ...
1
vote
3
answers
82
views
How to show an array of bytes as a string-like list of characters?
I am using a TCP-client program to catch a list of bytes, and when I send such a list of bytes, this is what I see:
I want to capture those characters in a logfile, so I did the following:
log.Debug($...
0
votes
0
answers
48
views
Flutter Object Box store image from URL
Does anyone know how we can store images obtained from a URL to object box ?
This is what i currently have:
@Entity()
class ServiceModel {
@Id()
int id = 0;
@Unique()
final String identifier;
...
0
votes
0
answers
73
views
What's wrong with this string to ByteArray type conversion?
I'm taking over an old VB.Net application, and there is some information, written in a string. I'm trying to decode this into a ByteArray but this fails:
Here's the code:
Dim sixthColumn As String = ...
0
votes
2
answers
101
views
VB.net Hex to byte array translated to C#
Hey all I am getting the following error when running this code:
byte[] bytes = new[] {
Convert.ToByte("&H" + Conversion.Hex(127)),
Convert.ToByte("&H" + Conversion....
0
votes
0
answers
37
views
Exiftool doesn't include all metadata when ran from python
class Metadata(Enum):
bit_rate_kbps: int
sample_rate: int
channel_mode: Literal['mono', 'audio']
file_name: str # includes extension
file_size: int # mb
file_ext: Literal['wav']...
0
votes
1
answer
76
views
Decoding X32 Behringer mixer response
I would like help please to get the 4 Return meter values (post gain/trim, gate, dyn gain reduction and post‐fade) from the X32 behringer mixer, these are in 32 bits floats, little‐endian coded. to ...
2
votes
1
answer
194
views
Unpredictable value when converting byte array to int | Eclipse Temurin-17.0.10+11
Problem statement:
I am encountering an issue when running the following multi-threaded program. The program spawns a large number of threads (10,000) that process the same byte array value. The issue ...
3
votes
2
answers
171
views
Ruby pack and unpack hex value does not return the same value?
I have a hex string of unknown (variable) length and I want to pack or unpack at any time to convert to bytes.
["a"].pack("H*")
# => "\xA0"
I'm getting \xA0 -- is ...
1
vote
0
answers
23
views
How to fix this error "Incorrect data types or column count mismatch when inserting rows" in GridDB
Cause: Incorrect data types or column count mismatch when inserting rows.
Solution:
Verify that the row data matches the container schema.
For Blob type, ensure the binary data is passed as a ...
-2
votes
1
answer
96
views
modifying items in byte[] arrays using loops (C#)
I got a byte[] array from an input file (ASCII text file) and I'm trying to delete all bytes of a pre-set hex value, without converting the array to string and without using lists.
This is the code I ...
1
vote
3
answers
149
views
signed int and unsigned int are equal based on bytes. but not signed char and unsigned char
Consider the following code:
signed a = -1;
unsigned b = UINT_MAX;
printf("%d\n", a==b);
signed char c = -1;
unsigned char d = UCHAR_MAX;
printf("%d\n", c==d);
The result will be:...
0
votes
2
answers
469
views
How can I convert a UInt32[] and a Int32[] array to byte arrays?
Trying to create a function that converts objects to byte arrays (without the overhead/metadata things like BinaryFormatter create). I think I'm happy with the following code except the ability of it ...
2
votes
1
answer
273
views
Reading C struct dumped into a file into Python Dataclass
Is there a consistent way of reading a c struct from a file back into a Python Dataclass?
E.g.
I have this c struct
struct boh {
uint32_t a;
int8_t b;
boolean c;
};
And I want to read it's data ...
1
vote
0
answers
38
views
Post file from memory stream
I want to upload a picture file without saving it to the hard disk (mainly because of performance). My code is as shown below.
Public Shared Function ConvertToByteArray(ByVal value As Bitmap) As Byte()...
-2
votes
1
answer
59
views
Why does hex give a different output than indexing into bytes in python?
I'm trying to confirm this struct is being formatted correctly for network byte order, but printing out the bytes and printing out the hex of the bytes give me different output, with the hex being the ...
1
vote
4
answers
227
views
Algorithmically finding the N-th byte of an integer in C
It is possible to find the value stored at an individual byte of memory of an int by creating a pointer of a byte type, such as char, and initializing to the address of the int. The code should look ...
1
vote
1
answer
561
views
The from_utf8 Rust function cannot read some ASCII strings (invalid utf-8 sequence of 1 bytes)
I am trying to convert a vector of ASCII bytes into a rust string. I found the std::str::from_utf8() function, that should be able to handle all ASCII strings. For some reason it cannot read the ...
0
votes
1
answer
68
views
Convert 0 to 255 to single Char
I am trying to convert values from 0 to 255 to a single char.
I am using chr. But this is somehow converting a number like 255 to a two char string.
I add up those values to a string which is then ...
-2
votes
1
answer
222
views
bytes().nth() vs chars().nth() in rust
I recently found out that bytes.nth(i) is waay faster than chars.nth(i) if you want to iterate over a String.
pub fn test(word1: String) {
for i in (0..word1.len()).rev() {
word1.bytes()....
0
votes
1
answer
415
views
Wiremock.net (C#) how to build a request matcher when the body is a an array of bytes
I need to build a WireMock.Net server for requests having body as bytes. I tried the matcher .WithBody combined with the converters Encoding.ASCII.GetBytes (and GetString) but with no success.
Thank ...
1
vote
3
answers
340
views
Handling byte strings in robot framework returns in null or blank
I have results returned from a function and storing it in a dictionary like this
${results}={'value': b'\x01\x00\x01\x00\x01\x00', 'type': None, 'error': None}
Now I want to extract only the value of ...
0
votes
1
answer
1k
views
UnicodeDecodeError: 'utf-8' codec can't decode byte 0xa0 in position ???: invalid start byte
I am working with byte strings that include non-ASCII characters, specifically Hebrew text, and I encountered a UnicodeDecodeError when trying to decode the byte string to UTF-8. Here's the ...
3
votes
1
answer
103
views
Handling multiple byte lengths within a WAV struct
I'm writing a .wav PCM file header in C, but one part I'm still stumped on handling is the bits per sample format parameter of a file. Right now I've only added support for 8-bit and 16-bit PCMs (...
0
votes
0
answers
54
views
Getting rowversion (timestamp) bytes to display value from database correctly?
I am looking for a solution to retrieve the hex I am storing in my VersionNum column of my database which is of type (timestamp, not null). I am using a SQL Server database.
VersionNum (timestamp, not ...
4
votes
2
answers
252
views
Byte functions in Visual Basic
Why does the VB expression
Asc(ChrB(128) & ChrB(0))
yield 63 and not 128?
Recently, I've been looking at Visual Basic's InputB function for reading binary data. According to the help system, ...
1
vote
0
answers
38
views
Undocumented bytes in .theme file format
According to Microsoft (https://learn.microsoft.com/en-us/windows/win32/controls/themesfileformat-overview#metrics-section), the Metrics section of a .theme file looks like
IconMetrics=76 0 0 0 139 0 ...
0
votes
3
answers
117
views
Binary integer representation printing in Linux / Shell
I have a Python scripts for printing a decimal string-represented integer as a 4-bytes little-endian representation:
import sys
i4 = int(sys.argv[1])
sys.stdout.buffer.write(i4.to_bytes(4, 'little'))
#...
1
vote
0
answers
52
views
Why does this padding function work alone but not as a PySpark UDF?
I have the following function:
def pad(array, target_size=(224, 224), pad_value=255):
# calculate padding
pad_h = (target_size[0] - array.shape[0]) // 2
pad_w = (target_size[1] - array....