Questions tagged [uint16]
127 questions
0
votes
1 answer
In C++11, why does int16_t have a size of 4 when declared after a float inside a struct?
I have a data structure like this:
struct mystruct
{
float f;
int16_t i;
};
sizeof(int16_t) gives 2, but sizeof(mystruct) gives 8 instead of 6. Why is that? How can I declare an int16_t variable of 2 bytes inside my data structure?

Jacky Lee
- 1,193
- 3
- 13
- 22
0
votes
1 answer
Pointer assignment - uint16_t
I was looking at a problem from cs61c (ucb).
I have the following method:
void lfsr_calculate(uint16_t *reg) {
uint16_t result = compute_bit_val(*reg);
printf("reg value: %d",…

Andrew
- 6,295
- 11
- 56
- 95
0
votes
1 answer
C - Arduino - cannot convert 'uint8_t*' to 'uint16_t*'
I am fairly new to C / Arduino
I am trying to simplify my code so that when I am writing my loop I will only require one function.
The code is for an SPI LCD display, i have two codes that I want to combine into one, the first code is to write 32…

Rob Brown
- 13
- 2
0
votes
1 answer
Swift, not Object-C: How to convert UInt8 / 16 to String?
For the project I am working on (using Swift, not Object-C!!!) I need to convert a UInt16 that I extracted from a BLE characteristic to a string, so I can use it as text for a label.
Anyone out there who already has solved this problem?
Thanks for…

Markus Schlüter
- 1
- 2
0
votes
1 answer
nodeJS Write integer to buffer using buffer.writeInt16BE
I want to ask, how to store a number (integer in JS) in buffer using buffer.writeInt16BE().
Assume I have a number such as
var a = 40000;
40000(10) = 9C40 (16)
how can I store 40000 in buffer of size of 2, so it looks something like:
<9c, 40>

tyrhus
- 181
- 1
- 9
0
votes
1 answer
C uint16 integer or char formatted?
I'm new on C programming and I'm testing some code where I receive and process an UDP packet formatted as follow:
UINT16 port1
UINT16 port2
The corresponding values on this test are:
6005
5555
If I print the whole packet buffer I get something…

Ezequiel Santos Pereira
- 5
- 1
- 3
0
votes
3 answers
C UINT16 How to get it right?
I'm new on C programming and I'm testing some code where I receive and process an UDP packet formatted as follow:
UINT16 port1
UINT16 port2
The corresponding values on this test are:
6005
5555
If I print the whole packet buffer I get something…

Ezequiel Santos Pereira
- 5
- 1
- 3
0
votes
1 answer
Convert two UInt16 Values to one UInt32 Value consider least and most significant word
I have two UInt16 values
private UInt16 leastSignificantWord;
private UInt16 mostSignificantWord;
The two words (UInt16 values) come from a component which divides a UInt32 status / error value into two words and returns the two words. Now i need…

Daniel W.
- 449
- 10
- 29
0
votes
0 answers
why do values get added to an nsmutablearray twice?
I am writing an app that communicates with a Bluetooth LE device and have a singleton that handles the connection. I want to store data values from the bluetooth device in an array for processing later on, and have the data values outputted to the…

skeg0
- 187
- 1
- 1
- 10
0
votes
2 answers
put uint16_t in uint32_t
char* createMSG(uint8_t i,uint16_t port) {
char *buff;
buff = (char*) calloc(1,6);
uint8_t id, tmp;
tmp = 0;
id = 2;
memcpy(buff, &id, sizeof(uint8_t));
memcpy(buff+1, &i, sizeof(uint8_t));
memcpy(buff+2, &port, sizeof(uint16_t));
memcpy(buff+2+2,…

user1324258
- 561
- 2
- 8
- 25
-1
votes
2 answers
Two's Complement Representation of int16_t
I am attempting to display a string representation of an int16_t's Two's Complement. I find the two's complement by (uint16_t)~value + 1;
How would I add the 16 bits to a string?
char* getBits(const int16_t value) {
uint16_t complement =…

Dawson Naccarato
- 21
- 7
-1
votes
1 answer
Why this uint16_t variable declaration doesn't work?
I have to send a package from a udp client to udp server (i made) but the problem is that this declaration doesn't work
#define RRQ 1
.
.
.
uint16_t op = htons(RRQ);
i tryed also
uint16_t op = htons(1);
and
int k = 1;
uint16_t op =…

Francesco
- 1
- 1
-1
votes
2 answers
How produce two's complement of a Uint16?
I have two bytes of data. I converted each of them to Uint8 then I produced a Uint16 from them.
How I can produce two's complement of this Uint16 number?
I've tried uInt16 = ~uInt16 + 1 but the code produces 32bit integer and I want it to stay a…

Behnam Shahabadi
- 3
- 3
-1
votes
1 answer
display image by using uint16array data
I am doing a DICOM project using XTK library. Now I need to create a list of thumbnails from input DICOM files (output images could be PNG or JPG).
During the rendering process, XTK provides an array of pixel data in an Uint16Array of each DICOM…

truongleit
- 1
- 3
-1
votes
1 answer
Error reading UInt16 from BinaryReader
Why does this work
Dim mem As New MemoryStream()
Dim bin As New BinaryWriter(mem)
bin.Write(CUShort(1000))
Dim read As New BinaryReader(New MemoryStream(mem.ToArray))
MsgBox(read.ReadInt16)
The message box give me 1000 which is right. Then I try to…

Adam
- 77
- 7