Is there a more efficient way of expanding a char to an uint64_t?

前端 未结 8 635
星月不相逢
星月不相逢 2021-01-18 06:32

I want to inflate an unsigned char to an uint64_t by repeating each bit 8 times. E.g.

char -> uint64_t
0x00 -> 0x00
0x01 ->         


        
8条回答
  •  小鲜肉
    小鲜肉 (楼主)
    2021-01-18 06:50

    If you're looking for efficiency use a lookup table: a static array of 256 entries, each already holding the required result. You can use your code above to generate it.

提交回复
热议问题