uint8_t (C language - Type). uint8_t stores an 8-bit unsigned number, from 0 to 255. It is equal to unsigned char.
Questions tagged [uint8t]
272 questions
7
votes
1 answer
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 do the following:
uint8_t my_intensity =…

ephtelule
- 91
- 2
6
votes
1 answer
Why does bitwise left shift promotes an uint8_t to a wider type
I was a bit messing around with uint8_t and was curious what happens when I outflow bits to the left and found that
uint8_t i = 234;
uint8_t j = (i << 1);
auto k = (i << 1);
std::cout << (int)j << std::endl;
std::cout << k <<…

Ackdari
- 3,222
- 1
- 16
- 33
6
votes
3 answers
structs with uint8_t on a MCU without uint8_t datatype
I am an Embedded Software developer and I want to interface to an external device. This device sends data via SPI. The structure of that data is predefined from the external device manufacturer and can't be edited. The manufacturer is providing some…

Muperman
- 344
- 2
- 14
6
votes
4 answers
Initialize huge uint8_t array statically with reasonable compilation time
I would like to statically initialize huge (megabytes) uint8_t array.
At the beginning I tried this:
constexpr uint8_t arr[HUGE_SIZE] = { 0, 255, ... };
Unfortunatelly, compilation time of above is very long (no optimization - around 30 seconds,…

mkk
- 675
- 6
- 17
6
votes
2 answers
Convert array of uint8_t to string in C++
I have an array of type uint8_t. I want to create a string that concatenates each element of the array. Here is my attempt using an ostringstream, but the string seems to be empty afterward.
std::string key = "";
std::ostringstream convert;
for (int…

Alex Parker
- 1,533
- 3
- 16
- 38
6
votes
2 answers
How can I convert uint8_t and uint16_t into floats in c++?
I created uint8_t and uint16_t variable types and read values into them from some registers. But, I'm unsure if I can easily cast these into float, and if the conversion will make numeric sense.
What is the optimal way to cast uint8_t, and uint16_t,…

Eneko
- 149
- 1
- 2
- 13
6
votes
1 answer
How do I use a typed array using a shared buffer efficiently in JavaScript?
In my code I have an object that contains a series of pixel coordinates. Performance of this object is critical because it's being used in a 60fps game where the output cannot always be cached.
After experimentation and benchmarking, a 3D array…

Blaise
- 13,139
- 9
- 69
- 97
5
votes
1 answer
C: Is there something wrong with declaring byte arrays as uint8_t?
I'm working on a small networking application that uses byte arrays. Traditionally these would be declared with something like char buf[] = ....
This seems to be how it is (still?) done in most tutorials, yet it has the problem that it may obscure…

gmolau
- 2,815
- 1
- 22
- 45
5
votes
1 answer
stringstream >> uint8_t in hex? c++
i am confused by the output of the following code:
uint8_t x = 0, y = 0x4a;
std::stringstream ss;
std::string a = "4a";
ss << std::hex << a;
ss >> x;
std::cout << (int)x << " "<< (int)y << std::endl;
std::cout << x << " "<< y…

user3402183
- 412
- 1
- 4
- 11
5
votes
4 answers
How to determine array length of uint8_t?
I'm trying to determine array length of msg on the below code. I used strlen and sizeof but they don't return 6. What function can I use to determine the length of uint8_t array or how can I modify the below code (osal_DataLenght() func)?
int…

sven
- 1,101
- 7
- 21
- 44
4
votes
4 answers
How to assign bitfield variable to uint8_t variable without violating MISRA rules?
I have a typedef struct named Character.
typedef struct {
unsigned int a : 1;
unsigned int b : 1;
unsigned int c : 1;
unsigned int d : 1;
unsigned int o : 1;
unsigned int p : 1;
unsigned int q : 1;
unsigned int x :…

Salahuddin
- 1,617
- 3
- 23
- 37
4
votes
0 answers
How do I make the Xcode debugger show uint8_t values as numbers?
The Xcode debugger expression window shows uint8_t values as their char equivalents.
So here m_interlace_delay is 0, m_column is 48, m_row is 10 and m_raster is 10.
What can I do to make Xcode display these values as numbers? I am happy for char…

Tom Seddon
- 2,648
- 1
- 19
- 28
4
votes
3 answers
How to turn a character array into uint8_t
I have a server-client application that I'm working on that basically simulates a chat room. This is an assignment for school and the protocol specifications are somewhat strict.
I have a char array which will store all messages from a client.
The…

fatalError
- 305
- 2
- 4
- 17
4
votes
2 answers
conversion of uint8_t to a string [C]
I'm trying to "translate" an array of uint8_t [uint8_t lets_try[16]] to a string of 16*8+1[null character] elements. For example:
lets_try[0] = 10101010
lets_try[1] = 01010101
...
and I would like to have a string…

Antonino
- 3,178
- 3
- 24
- 39
4
votes
2 answers
How to work with uint8_t instead of char?
I wish to understand the situation regarding uint8_t vs char, portability, bit-manipulation, the best practices, state of affairs, etc. Do you know a good reading on the topic?
I wish to do byte-IO. But of course char has a more complicated and…

peterf
- 43
- 1
- 3