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)'�';
...
994
votes
21
answers
2.0m
views
Converting string to byte array in C#
I'm converting something from VB into C#. Having a problem with the syntax of this statement:
if ((searchResult.Properties["user"].Count > 0))
{
profile.User = System.Text.Encoding....
504
votes
35
answers
608k
views
Correct way to convert size in bytes to KB, MB, GB in JavaScript
I got this code to covert size in bytes via PHP.
Now I want to convert those sizes to human readable sizes using JavaScript. I tried to convert this code to JavaScript, which looks like this:
...
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 ...
679
votes
37
answers
944k
views
MySQL Error #1071 - Specified key was too long; max key length is 767 bytes
When I executed the following command:
ALTER TABLE `mytable` ADD UNIQUE (
`column1` ,
`column2`
);
I got this error message:
#1071 - Specified key was too long; max key length is 767 bytes
...
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 ...
924
votes
11
answers
2.4m
views
"TypeError: a bytes-like object is required, not 'str'" when handling file content in Python 3
I've very recently migrated to Python 3.5.
This code was working properly in Python 2.7:
with open(fname, 'rb') as f:
lines = [x.strip() for x in f.readlines()]
for line in lines:
tmp = line....
-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 ...
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. ...
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 ...
462
votes
25
answers
653k
views
Convert a string representation of a hex dump to a byte array using Java?
I am looking for a way to convert a long string (from a dump), that represents hex values into a byte array.
I couldn't have phrased it better than the person that posted the same question here.
But ...
176
votes
31
answers
214k
views
Does .NET provide an easy way convert bytes to KB, MB, GB, etc.?
Just wondering if .NET provides a clean way to do this:
int64 x = 1000000;
string y = null;
if (x / 1024 == 0) {
y = x + " bytes";
}
else if (x / (1024 * 1024) == 0) {
y = string.Format("{0:...
407
votes
10
answers
331k
views
What is the difference between a string and a byte string?
I am working with a library which returns a "byte string" (bytes) and I need to convert this to a string.
Is there actually a difference between those two things? How are they related, and ...
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 "...
-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"...
227
votes
19
answers
303k
views
How do I convert Long to byte[] and back in java
How do I convert a long to a byte[] and back in Java?
I'm trying convert a long to a byte[] so that I will be able to send the byte[] over a TCP connection. On the other side I want to take that byte[...
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
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 ...
235
votes
15
answers
478k
views
Java integer to byte array
I got an integer: 1695609641
when I use method:
String hex = Integer.toHexString(1695609641);
system.out.println(hex);
gives:
6510f329
but I want a byte array:
byte[] bytearray = new byte[] { (...
-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 ...
194
votes
8
answers
560k
views
Convert bytes to int?
I'm currently working on an encryption/decryption program and I need to be able to convert bytes to an integer. I know that:
bytes([3]) = b'\x03'
Yet I cannot find out how to do the inverse. What am ...
220
votes
13
answers
120k
views
Why is a boolean 1 byte and not 1 bit of size?
In C++,
Why is a boolean 1 byte and not 1 bit of size?
Why aren't there types like a 4-bit or 2-bit integers?
I'm missing out the above things when writing an emulator for a CPU
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\...
231
votes
13
answers
780k
views
Is the size of C "int" 2 bytes or 4 bytes?
Does an Integer variable in C occupy 2 bytes or 4 bytes? What are the factors that it depends on?
Most of the textbooks say integer variables occupy 2 bytes.
But when I run a program printing the ...
193
votes
12
answers
644k
views
Java Byte Array to String to Byte Array
I'm trying to understand a byte[] to string, string representation of byte[] to byte[] conversion... I convert my byte[] to a string to send, I then expect my web service (written in python) to echo ...
143
votes
14
answers
499k
views
Byte array to image conversion
I want to convert a byte array to an image.
This is my database code from where I get the byte array:
public void Get_Finger_print()
{
try
{
using (SqlConnection thisConnection = new ...
162
votes
13
answers
351k
views
Convert any object to a byte[]
I am writing a prototype TCP connection and I am having some trouble homogenizing the data to be sent.
At the moment, I am sending nothing but strings, but in the future we want to be able to send ...
209
votes
11
answers
1.0m
views
How do I initialize a byte array in Java?
I have to store some constant values (UUIDs) in byte array form in java, and I'm wondering what the best way to initialize those static arrays would be. This is how I'm currently doing it, but I feel ...
122
votes
14
answers
280k
views
How to convert a byte to its binary string representation
For example, the bits in a byte B are 10000010, how can I assign the bits to the string str literally, that is, str = "10000010".
Edit
I read the byte from a binary file, and stored in the ...
102
votes
4
answers
173k
views
How to convert bytes type to dictionary [duplicate]
I have a bytes type object like this:
b"{'one': 1, 'two': 2}"
I need to get proper python dictionary from the above bytes type object using python code.
string = b"{'one': 1, 'two': 2}&...
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 ...
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($...
131
votes
14
answers
232k
views
What's the difference between a word and byte?
I've done some research.
A byte is 8 bits and a word is the smallest unit that can be addressed on memory. The exact length of a word varies. What I don't understand is what's the point of having a ...
3
votes
2
answers
172
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 ...
147
votes
14
answers
188k
views
How many bytes in a JavaScript string?
I have a javascript string which is about 500K when being sent from the server in UTF-8. How can I tell its size in JavaScript?
I know that JavaScript uses UCS-2, so does that mean 2 bytes per ...
163
votes
4
answers
227k
views
How to know the size of the string in bytes?
I'm wondering if I can know how long in bytes for a string in C#, anyone know?
163
votes
10
answers
243k
views
How to Get True Size of MySQL Database?
I would like to know how much space does my MySQL database use, in order to select a web host.
I found the command SHOW TABLE STATUS LIKE 'table_name' so when I do the query, I get something like this:...
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 ...
109
votes
6
answers
204k
views
Hashing with SHA1 Algorithm in C#
I want to hash given byte[] array with using SHA1 Algorithm with the use of SHA1Managed.
The byte[] hash will come from unit test.
Expected hash is 0d71ee4472658cd5874c5578410a9d8611fc9aef (case ...
131
votes
10
answers
248k
views
How to convert from []byte to int in Go Programming
I need to create a client-server example over TCP. In the client side I read 2 numbers and I send them to the server. The problem I faced is that I can't convert from []byte to int, because the ...
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 ...
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 ...
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 ...
95
votes
11
answers
211k
views
In Go, how can I convert a struct to a byte array?
I have an instance of a struct that I defined and I would like to convert it to an array of bytes. I tried []byte(my_struct), but that did not work. Also, I was pointed to the binary package, but I am ...