Questions tagged [uint16]
127 questions
38
votes
1 answer
error: 'uint16_t' undeclared?
I have the code
#include
#include
void print128_num(__m128i var)
{
uint16_t *val = (uint16_t*) &var;
printf("Numerical: %i %i %i %i %i %i %i %i \n",
val[0], val[1], val[2], val[3], val[4], val[5],
…

pandoragami
- 5,387
- 15
- 68
- 116
31
votes
3 answers
How do I printf() a uint16_t?
I need to use printf() to print a uint16_t. This SO answer (How to print uint32_t and uint16_t variables value?) says I need to use inttypes.h.
However, I'm working on an embedded system and inttypes.h is not available. How do I print a uint16_t…

user9993
- 5,833
- 11
- 56
- 117
14
votes
3 answers
Unpack binary data with python
I would like to unpack an array of binary data to uint16 data with Python.
Internet is full of examples using struct.unpack but only examples dealing with binary array of size 4.
Most of these examples are as follow (B is a binary array from a…

Alan Turing
- 141
- 1
- 1
- 5
10
votes
3 answers
Swift: Convert Int16 to Int32 (or NSInteger)
I'm really stuck! I'm not an expert at ObjC, and now I am trying to use Swift. I thought it would be much simpler, but it wasn't. I remember Craig said that they call Swift “Objective-C without C”, but there are too many C types in OS X's…

Wilson Luniz
- 459
- 2
- 7
- 18
9
votes
2 answers
Uint16Array to Uint8Array
I have a basic question. Say I have a Uint16Array and I have number 4 in it.
data_16=new Uint16Array([4]);
Now I have a length 1 and byteLength 2;
how do i convert this to Uint8Array.
I do not want to create a new view.
data_8 = new…

Evren Bingøl
- 1,306
- 1
- 20
- 32
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
5
votes
4 answers
array of UInt16, what's the suffix in C#?
I'm trying to initialize inline an array of UInt16. For int I can do the following:
int[] int_array = new[]{0,0,0,0};
meanwhile using UInt16 doesn't work without a cast:
UInt16[] uint16_array= new[]{(UInt16)0,(UInt16)0};
It's quite annoying do…

Heisenbug
- 38,762
- 28
- 132
- 190
5
votes
4 answers
Extract upper and lower word of an unsigned 32-bit integer
To extract the upper and lower word of an unsigned 32-bit integer and store each one in separate uint16_t-variables I do as follows (nbr is an unsigned 32-bit integer):
uint16_t lower_word = (uint16_t) nbr & 0x0000FFFF; // mask desired…

Abdel Aleem
- 667
- 10
- 15
4
votes
1 answer
Why is CDROM_TOC.Length an UCHAR[2] instead of WORD?
In the documentation the length is made of two unsigned bytes:
Length
Indicates the length, in bytes, of the table of contents data. This length value does not include the length of the Length member itself.
When you form a WORD in Little Endian,…

aybe
- 15,516
- 9
- 57
- 105
4
votes
1 answer
printing uint16_t type
I'm reading a file in binary mode this way:
fread(&pcap_header ,sizeof(pcap_hdr_t ), 1 , pFile);
fread(&pcaprec_header ,sizeof(pcaprec_hdr_t ), 1 , pFile);
fread(ðer_header ,sizeof(ethernet_hdr_t ), 1 ,…

nerez
- 437
- 4
- 18
3
votes
1 answer
Proper way for casting uint16 to int16 in Go
Bitwise manipulation and Go newbie here :D I am reading some data from sensor with Go and I get it as 2 bytes - let's say 0xFFFE. It is easy too cast it to uint16 since in Go we can just do uint16(0xFFFE) but what I need is to convert it to integer,…

Devligue
- 413
- 5
- 16
3
votes
2 answers
How to convert HEX string to UInt16?
I have a HEX string d285 and I want to convert it UInt16, please guide me how I can convert it. I tried this
let buffer = UInt16("\(UInt8(text, radix: 16)!)")
return Data(bytes: (buffer?.bigEndian.toBytes)!)
but it's not working

Varun Naharia
- 5,318
- 10
- 50
- 84
3
votes
1 answer
Python 3.4: Converting ushort to bytes
I'm trying to convert a ushort to bytes. However, when I try this:
>>import struct
>>val =struct.pack('

Kucosyn
- 49
- 6
3
votes
2 answers
Convert usigned integer( uint16_t) to string. Standard itoa base 10 is giving negative values
I need to convert uint16_t value to a string. I want the string to be a decimal respresentation of the number.
Example: uint16_t i=256 string: 256
I tried with itoa(i,string, 10) but when i value increases starts printing negative values.
I send the…

user3278790
- 75
- 1
- 3
- 9
3
votes
2 answers
How to convert a char array to a uint16_t by casting type pointer?
char bytes[2];
bytes[0] = 0; //0x00
bytes[1] = 24; //0x18
uint16_t* ptrU16 = (uint16_t*)bytes; // I expect it points to the memory block: 0x18
cout << *ptrU16 << endl; // I expect 24, but it is 6144
What's wrong in my code?

FEL
- 33
- 1
- 3