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...
You can use the buffer property, i.e. data_8 = new Uint8Array(data_16.buffer).
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...
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; }...
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); } }...
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...
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...