Questions tagged [uint8t]

uint8_t (C language - Type). uint8_t stores an 8-bit unsigned number, from 0 to 255. It is equal to unsigned char.

272 questions
217
votes
8 answers

uint8_t can't be printed with cout

I wrote a simple program that sets a value to a variable and then prints it, but it is not working as expected. My program has only two lines of code: uint8_t a = 5; cout << "value is " << a << endl; The output of this program is value is , i.e.,…
CoderInNetwork
  • 2,923
  • 4
  • 22
  • 39
66
votes
2 answers

reinterpret_cast between char* and std::uint8_t* - safe?

Now we all sometimes have to work with binary data. In C++ we work with sequences of bytes, and since the beginning char was the our building block. Defined to have sizeof of 1, it is the byte. And all library I/O functions use char by default. All…
user3624760
66
votes
3 answers

When is uint8_t ≠ unsigned char?

According to C and C++, CHAR_BIT >= 8. But whenever CHAR_BIT > 8, uint8_t can't even be represented as 8 bits. It must be larger, because CHAR_BIT is the minimum number of bits for any data type on the system. On what kind of a system can uint8_t be…
user541686
  • 205,094
  • 128
  • 528
  • 886
35
votes
4 answers

Convert byte slice "[]uint8" to float64 in GoLang

I'm trying to convert a []uint8 byte slice into a float64 in GoLang. I can't find a solution for this issue online. I've seen suggestions of converting to a string first and then to a float64 but this doesn't seem to work, it loses it's value and…
user3435186
  • 361
  • 1
  • 3
  • 4
20
votes
3 answers

Convert vector of uint8 to string

I have a pointer to a vector of type uint8. How would I take this pointer and convert the data in the vector into a full string representative of its content?
Mr S
  • 458
  • 3
  • 7
  • 15
15
votes
1 answer

converting int to uint8_t

is it a correct way to convert an int value to uint8_t: int x = 3; uint8_t y = (uint8_t) x; assume that x will never be less than 0. Although gcc does not give any warning for the above lines, I just wanted to be sure if it is correct to do it or…
Johan Elmander
  • 497
  • 2
  • 6
  • 11
14
votes
1 answer

Identifier uint8_t is undefined - Visual Studio 2017

I get an error with the type definitions. I am working with Visual Studio 2017 and so I included stdint.h for the type definitions. But I still have the Problem that the identifier uint8_t is undefined. What's the problem?
Sinem
  • 143
  • 1
  • 1
  • 4
13
votes
4 answers

Convert a float to 4 uint8_t

I have got a float variable that I need to send through a CAN protocol. To do so, this float of 32 bits must be cut in 4 uint8_t variables. I have absolutely no idea of how to do. I was first thinking of convert the float to an int but some answers…
13
votes
4 answers

Convert char* to uint8_t

I transfer message trough a CAN protocol. To do so, the CAN message needs data of uint8_t type. So I need to convert my char* to uint8_t. With my research on this site, I produce this code : char* bufferSlidePressure =…
Evans Belloeil
  • 2,413
  • 7
  • 43
  • 76
12
votes
2 answers

What are the advantages of using Uint8List over List when dealing with byte arrays in Dart?

I'm writing a Dart library in which I'm very regularly dealing with byte arrays or byte strings. Since Dart doesn't have a byte type nor an array type, I'm using List for all byte arrays. Is this a good practice to do? I only recently found out…
Steven Roose
  • 2,731
  • 4
  • 29
  • 46
10
votes
1 answer

How to deal with uint8_t on a Python Extension?

I would like to pass as argument of a function in my C module an array of uint8_t's. I couldn't find a method to directly parse this array, so I'm parsing it to a PyObject_t and then iterating as a PyTuple_t object. This way, I need to cast each…
Pedro Alves
  • 1,667
  • 4
  • 17
  • 37
9
votes
3 answers

uint8_t not rollover to 0 after reaching 255 not working properly

I am new to the C-Headers - stdint.h and inttypes.h. I was trying out some code to get an inkling of how uint8_t works. But, it seems to have encountered a problem. I have declared 4 uint8_t integers with the boundary values 0, 255, 256, -1…
TejasKhajanchee
  • 103
  • 2
  • 8
9
votes
2 answers

Convert from uint8_t * to char * in C

I am programming in C using Atmel Studio (for those unfamiliar with this it is used to program to micro controllers such as arduino. You can not simply print, you have to send the data Serially to an application such as Terminal.) I have so…
skyleguy
  • 979
  • 3
  • 19
  • 35
8
votes
1 answer

can I assume that sizeof(uint8_t) = 1?

I have a program that uses dynamic allocation for a uint8_t array; can I safely assume that its length will always be one byte?
Tom
  • 105
  • 1
  • 1
  • 6
8
votes
2 answers

1 byte integer data type

I wrote the following code: #include #include #include using namespace std; int main() { uint8_t c; cin >> hex >> c; cout << dec << c; return 0; } But when I input c—hex for 12—the…
AvinashK
  • 3,309
  • 8
  • 43
  • 94
1
2 3
18 19