Menu
  • HOME
  • TAGS

How to convert a char array to a uint16_t by casting type pointer?

c++,casting,uint16

You have a little endian machine. 6144 is 0x1800. When your machine represents the 16 bit value 0x0018 in memory, it puts the 0x18 byte first, and the 0x00 byte second, so when you interpret the two byte sequence 0x0018 as a uint16_t, it gives you 6144 (i.e. 0x1800), and...

Uint16Array to Uint8Array

javascript,arraybuffer,uint16

You can use the buffer property, i.e. data_8 = new Uint8Array(data_16.buffer).

How to bit-shift and concatenate to get correct result?

c#,concatenation,bit,bit-shift,uint16

I already tried to (logically) bit-rightshift r[0] by 8, but then the upper bits get lost because they are stored in the first 8 bits of r[1]. Well they're not "lost" - they're just in r[1]. It may be simplest to break it down step by step: byte val1LowBits...

a gettime() function that returns a uint16_t value in C

c,time.h,gettime,uint16

uint16_t getD() { time_t ti; ti = time(NULL); struct tm tm_time; tm_time = *localtime(&ti); //const time_t create_time; uint16_t t, d; d = tm_time.tm_mday + (tm_time.tm_mon + 1) * 32 + (tm_time.tm_year - (1980-1900)) * 512; // Print ddmmyy printf("%02d%02d%02d\n", (int) d%32, (int) (d/32)%16, (int) ((d/512)%128 + (1980-1900))%100); return d; }...

C - Arduino - cannot convert 'uint8_t*' to 'uint16_t*'

c,arduino,lcd,uint8t,uint16

void* will solve your cast problem and sizeof a pointer is never going to be > 33 so try this instead: void LCD(char RGBXXX, void *str, int is_data) { RGB(RGBXXX); if (is_data != 0) { char data[33]; memcpy(data,(uint8_t*)str,33); writeLCD(data); } else { BMP((uint16_t *)str); } }...

In C++11, why does int16_t have a size of 4 when declared after a float inside a struct?

c++11,alignment,structure,sizeof,uint16

That is because of padding, given your system's architecture, the compiler adds some space to the structure. If you try to add another int16_t, you'll see that the size of this structure will still be 8. struct mystruct { float f; std::int16_t i; std::int16_t g; }; In your original case...

Pointer assignment - uint16_t

c,pointers,uint16

In the last step, you assign 65536 to *reg which is uint16_t. However uint16_t can only store values from 0 to 65535, so it gets adjusted via modular arithmetic to have value 0. (aka. wraps around). You may be overlooking that integer arithmetic is always performed in at least int...