c - RGBA Hex from RGB Hex -



c - RGBA Hex from RGB Hex -

i want create color 0xff0000 (rgb), rgba color ff alpha, 0xff0000ff. bits, think.

thanks in advance, kacper

uint32_t rgb=0xff0000; uint32_t rgba = (rgb << 8) | 0xff;

explanation: (rgb << 8) shifts rgb value 8 bits left. means moves 1 byte left illustration 0x12345678 alter 0x34567800. top 2 digits won't fit in 32 bits after shifting, removed. every thing else shifts left , new zeroes added in low position.

the next operator bitwise or. it's or applied on every bit 0x34567800 | 0xff result in 0x345678ff

(thanks @gajet explanation)

c colors hex rgb rgba

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -