I am looking for an elegant alternative of the following code where wordXX contains always 16 bits:uint64_t wordHi = 0xaa; // I would like u_int16_t over u_int64_t hereuint64_t wordMi = 0xbb; // because it represents the real data betteruint64_t wordLo = 0xcc;uint64_t largeword = (wordHi << 32) + (wordMi << 16) + (wordLo << 0);To me this (very simplified) code looks a bit dirty, because reader gets confused about the real size of the wordXX data. I could store wordHi to largeword and then shift largeword and add wordMi and so on, but this would make the code worse and probably needs more CPU cycles. Edit: changed u_int64_t to uint64_t in the example as suggested in the comments.
Concatenate three 16-bit integers in one 64-bit integer with C++
c++;performance;integer;bitwise
Using uint16_t not a problem?Your comment says you want to use uint16_t, so why don't you do that?  It would make the code look like this:uint16_t wordHi = 0xaa;uint16_t wordMi = 0xbb;uint16_t wordLo = 0xcc;uint64_t largeword = ((uint64_t) wordHi << 32) + ((uint64_t) wordMi << 16) + wordLo;