283 questions
0
votes
3
answers
529
views
How to cleanly work with enum class and uint8_t without excessive static_cast?
I'm currently working on a performance-oriented chess move generator and using lots of strongly-typed enum class declarations for things like Square, File, Rank, Color, PieceType, Castling, Direction ...
0
votes
1
answer
46
views
Understanding SetArgPointee behavior, and conversion errors
I have a class Bar, with a reference of a class Foo which have a read method. I'm trying to unit test, using gtest, the behavior of the public method Bar::test(), which does something different based ...
3
votes
2
answers
165
views
Check if uint8_t array contains string
In C language I have a uint8_t array and, after some logic, I need to cast to string and check if contains some substring like this:
uint8_t data[8] = {0xcb,0xe2,0x3d,0x96,0x55,0xfc,0xcd,0x43};
//...
1
vote
2
answers
324
views
About the use of uint8_t in C when counting
I wanted to make sure that I understood what is happening in the following code:
#include <stdio.h>
#include <stdint.h>
int main (void)
{
uint8_t a = 255;
a = a + 5;
printf(&...
0
votes
1
answer
444
views
string_view<uint8_t>
I have a big vector of bytes, and I want to take a part of it, interpret these bytes as ASCII characters written in hexadecimal system and print this substring on the screen. I don't need a copy, so I ...
1
vote
1
answer
196
views
Is cast from uint8_t* to char* acceptable
Concerning this question
Convert from uint8_t * to char * in C
The suggestion was simply to cast with (char*). Why is this acceptable in this context? Or did the responder just take the question ...
2
votes
1
answer
409
views
In C++, why would you use `uint8_t` to declare a string? [closed]
As a mobile developer working with React Native, I need to work with a C++ code that creates and encrypts files. I don't have much experience with C++ (the last time I wrote some was over 15 years ago ...
0
votes
1
answer
136
views
Casting uint8_t* to int16_t8 in C
I am attempting to adapt an example from here which reads PDM microphone data and prints it to a computer using serial USB.
I want to bypass the filtering stage in the example so I can write my own ...
0
votes
1
answer
712
views
PN532 RFID with ESP32 (ESP-IDF) Passing uint8_t UID to a string
I am trying to write a fairly basic program in platformio using the esp-idf framework for an esp32. I have the main bits working, but i'm struggling with something that I thought would be very basic!
...
0
votes
4
answers
510
views
How can a double be converted to bytes to be stored in c++?
I am trying to write a program that can take a list of a specific type for example a double or float and convert it into bytes and write it to a file that can be converted back into that original list....
0
votes
1
answer
1k
views
Convert a vector of 3 uint8 to a uint32 in simulink
I had a vector of 3 elements all type uint8 that need to be converted to a uint32, I’m struggling to find the correct block to do that I tried unpacking the signals but then that creates a problem ...
-2
votes
2
answers
387
views
How to convert 32-bit binary value to int8_t array
I'm trying to covert a 32 bit binary value into int8_t array. I'm not sure how to do this, and I'm struggling to find any documentation explaining the process.
I was thinking that each 8 bits ...
0
votes
0
answers
426
views
uint8_t element assignment to uint8_t array in C++
I am trying to create a uint8_t array and try to change the first element of the array, then print it to the terminal as a string.
But, after I assign currBlock (changed block) to arr[0], cout gives ...
0
votes
1
answer
161
views
How to add a uint8_t array into a char*
I have a char *data that is a Datagram to represent the packet I want to send in but I need to insert on that an uint8_t array.
// Datagram to represent the packet
char datagram[4096], source_ip[32], *...
0
votes
0
answers
44
views
if stament with uint8_t
knowing the value of the variable tempStatusSelectorByte is 0, in the if stament it is giving true for tempStatusSelectorByte>4.
uint8_t tempStatusSelectorByte;
tempStatusSelectorByte = ...
0
votes
2
answers
2k
views
convert struct to uint8_t array in C++
I have a typedef struct with different data types in it. The number array has negative and non-negative values. How do I convert this struct in to a unint8t array in C++ on the Linux platform. ...
0
votes
0
answers
112
views
How to store negative number in a uint_8 array
I am trying to send some data with BLE from an STM32 board to an Raspberry Pi 3B board. However, the "write" function of BLE API only supports uint8_t array transfer, but the data I need to ...
2
votes
1
answer
1k
views
How to convert a QString containing a hex value to an uint?
QString samp_buff[100];
QByteArray data;
uint8_t speed;
samp_buff[3] = data.toHex(); //I converted the QByteArray into a string
qDebug() << "read_every_data_"<< samp_buff[3];
...
-1
votes
1
answer
295
views
How to convert char array to uint8_t and print it in c?
I have a decimal number and we have converted it to hex and have stored in a hex array. After that I added a "0x" to this number (in fact char array). Now I want to convert this hex number (...
2
votes
1
answer
1k
views
Copy const char* to uint8_t array
My C-API takes an array of uint8_t's as config parameter. I'm arriving at its doorsteps with a const char*. How do I now copy the chars over to the uint8_t array in the most unproblematic way? Here's ...
0
votes
1
answer
1k
views
Passing String to a function that takes uint8_t in C
I want to send a string over UART but the function that sends data over UART accepts uint8_t as an argument.
The function prototype: UART2_Write(uint8_t txData);
I wish to send an 8-character long ...
1
vote
0
answers
119
views
crash when clearing uint8_t on pic18f67k22
I'm adding a clock to my program, but for some reason I cannot lower the value of my "sec" variable.
I have a millisecond timer that raises a flag every ms. So, every 1000 ms I clear the ms ...
0
votes
1
answer
2k
views
string into const uint8_t*
I'm writing a program in C++/C for raspberry pi pico. Pico has a 2MB of flash memory and it's SDK provides a function which allows to write data to that memory:
void flash_range_program(uint32_t ...
0
votes
1
answer
449
views
How to convert a char16_t into a stringstream divided with 2 bytes
I made a utf8 to utf16 conversion where i get the code units for the utf16 char16_t.
{
std::string u8 = u8"ʑʒʓʔ";
// UTF-8 to UTF-16/char16_t
std::u16string u16_conv = std::...
0
votes
0
answers
171
views
I'm trying to drop a dummy variable as type uint8 but I keep getting an error "['False'] not found in axis". Tks for the support as I'm new to this
data.columns
Data
dummy = pd.get_dummies(data['High_or_Low_Balance'])
data2 =pd.concat((data, dummy), axis=1)
data2 = data2.drop(['High_or_Low_Balance'], axis=1)
data2.rename(columns={"True&...
0
votes
0
answers
298
views
Lack of understanding when fread a file into an array
I'm doing CS50 (Week 4 Lab 4 Volume) and I have to copy a header from an input WAV file to output file (the 44 first bytes).
To start, I created the array uint8_t header[HEADER_SIZE];. Then, I used ...
0
votes
1
answer
693
views
javascript: from a websocket I receive messages as zlib deflate: how to read OR "unflate" OR "deflate" (not inflate)
This question is about converting a gzip deflate message from a websocket message and convert it to array OR raw text that I can apply JSON.parse on it...
*** to be also clear: In this question : i ...
0
votes
0
answers
409
views
Argtypes: uint8_t from C to Python
I'm using ctypes to use a C library in my python script.
I have a function in C library that accepts as argtypes uint8_t and was wondering how to invoke it from python.
This is the C function I'm ...
1
vote
2
answers
627
views
Convert Int64 array to Int8 in Julia gives InexactError: trunc(Int8, -9223372036854775808)
I try to convert a part of an julia df from Int64 to Int8.
input:
array = convert(Array{Int8} , array );
output:
InexactError: trunc(Int8, -9223372036854775808)
Stacktrace:
[1] throw_inexacterror(...
0
votes
1
answer
2k
views
Converting uint8_t array to a char array or string in C [duplicate]
How can I convert a uint8_t array to a char array or string in C?
uint8_t array[10];
0
votes
1
answer
686
views
Why is data bytes size different when serialized with JSONSerialization
Why is data serialized using JSONSerialization differ from the data serialized with the extension below?
let uint8Array: [UInt8] = [123, 234, 255]
let data1 = uint8Array.data // 3bytes
let data2 = try!...
0
votes
1
answer
562
views
Creating an array using uint8_t (CS50 Lab4: Volume)
I am working on lab 4 of CS50 course which requires to read the header of an input file which is always 44 bytes and write it as the header of the output file. Below is the correct solution.
const ...
2
votes
1
answer
418
views
Overloading function with char and uint8_t types
To implement a basic interface for an LCD I need to write the function print for all basic types. I need to write
void print(char c);
and also
void print(uint8_t c);
The first function tells: "...
2
votes
1
answer
1k
views
Dart : Index out of range: index should be less than N: N (where N is the size of file in bytes). How to fix this runtime error?
I am trying to decode some animated webp files in dart but getting the runtime error of 'index out of range and it should be less than N. and N is the size of file in bytes. But images other than this ...
7
votes
1
answer
220
views
Can I make a calculation with a value outside of the range of my variable?
I'm coding in C and I know the values that can be stored in a uint8_t range from 0 to 255. I want to store a value that is the percentage of MAX_INTENSITY, declared as:
#define MAX_INTENSITY 200
Can I ...
0
votes
0
answers
113
views
sysfs_store sscanf u8 from buffer not working correctly
// userspace
uint8_t value = 5;
write (fd, (const char *)&value, 1);
// kernel driver
static ssize_t sysfs_store(struct kobject *kobj, struct kobj_attribute *attr, const char *buf, size_t count)
{...
0
votes
1
answer
879
views
Audio transmitted in uint8_t into a .wav file
I am trying to transmit audio using CAN FD and the data format it sends it is in uint8_t, when the sample I take from the microphone with the ADC is an uint32_t. Will I have any problem trying to ...
1
vote
0
answers
798
views
C++ Convert to hex and store the result in uint8_t
std::stringstream sstream;
uint8_t data[1] = { };
int x =1;
sstream << "0x" << std::hex << x; //sstream = 0x04b35cc8 "0x1" why the sstream not be only ...
0
votes
0
answers
16
views
Converting uint8_t hex to string hex in C [duplicate]
In this case, i use an algorithm hashing to implementating blockchain, and then my algorithm is working properly but the output need to return string. This is my function to try only print the output ...
0
votes
1
answer
2k
views
How to reconstruct a 4 byte uint8 array into a uint32 integer
I have a web app (javascript) that needs to send a arduino(ESP32) a 12bit value (0x7DF).
I have a websocket connection that only accepts a Uint8_t payload, so I split the value into 4 bytes (Uint8_t).
...
0
votes
0
answers
439
views
How can I change a uint8_t array into an array of integers?
How can I change a uint8_t array into an array of integers? For example if I want to print the numbers in the uint8_t array array_beam_sx I have to write:
cout<<+array_beam_sx[0];
to see the ...
0
votes
1
answer
93
views
Is the value of my conversion correct? Hex string to byte array
I've the following issue:
from a socket, I receive an hexadecimal string, then I convert it to a byte array and save it into a uint8_t array. Here is the conversion function (it works):
static size_t ...
0
votes
1
answer
361
views
C++ template class crashing by uint8_t type only
I've just found this interesting issue in one of my older projects.
I'd defined a class wrapped around an std::shared_ptr to implement a simple dynamic array as you can see below:
#include <memory&...
-2
votes
3
answers
212
views
Why does my data is cut when I have 0x00?
I want to copy an uint8_t array to a uint8_t pointer
uint8_t temp_uint8_array[] = {0x15, 0x25, 0x32, 0x00, 0x52, 0xFD};
uint8_t* Buffer = temp_uint8_array;
And now :
Buffer = {0x15, 0x25, 0x32};
So ...
-2
votes
1
answer
1k
views
Convert char* data to uint16_t* or uint16_t array in C
My Arduino program receives a char* text message like this:
char* messageFromWebSocket = "4692\n4408\n656\n358\n662\n356\n658\n376\n656\n358\n662\n1394\n660\n1392\n636\n378\n632\n382\n638\n1418&...
1
vote
3
answers
842
views
initialize uint8_t array from txt file
I have, in a .txt file, a uint8_t array already formatted, like this:
0x4d, 0x5a, 0x90, 0x00, 0x03, 0x00, 0x00, 0x00, 0x04, 0x00, 0x00, 0x00, 0xff, 0xff, 0x00, 0x00,
0xb8, 0x00, 0x00, 0x00, 0x00, 0x00,...
2
votes
3
answers
560
views
Unable to create 2D vector in CPP std::vector<std::vector<uint8_t>> by just giving the size
I was creating empty 2D vector in a header file by just providing size but unable to create it.
class Grid
{
public:
int rows = 5/0.05;
int cols = 6/0.05;
...
1
vote
0
answers
36
views
enum size and initialization of variable [duplicate]
Even setting the size of an enum is not enough to be able to assign it to a variable of the same size (http://coliru.stacked-crooked.com/a/edd287393f172abd):
#include <iostream>
#include <...
0
votes
0
answers
209
views
Get first three characters from array elements
Trying to print the array elements, like below:
typedef struct Info
{
UINT32 freq[8];
} Info;
char FREQ[100];
sprintf(FREQ, "%u %u%c", Info->freq[0], Info->...
0
votes
1
answer
979
views
How to convert a uint8_t array into a string?
I've a function that can convert an hexadecimal string (ex. "02AFA1253...ecc.") into an uint8_t array. I would need to do the opposite, which is to convert the uint8_t array to a string of ...