concatenation - How to combine 2 4-bit unsigned numbers into 1 8-bit number in C -
i have 2 4-bit numbers (x0x1x2x3 , y0y1y2y3) , want combine them create 8-bit number that:
x0x1x2x3 y0y1y2y3 => x0y0x1y1x2y2x3y3
i know how concatenate them in order create x0x1x1x3y0y1y2y3
stuck on how compose them in pattern explained above.
any hints?
here's direct way of performing transformation:
uint8_t result; result |= (x & 8) << 4; result |= (y & 8) << 3; result |= (x & 4) << 3; result |= (y & 4) << 2; result |= (x & 2) << 2; result |= (y & 2) << 1; result |= (x & 1) << 1; result |= (y & 1) << 0;
Comments
Post a Comment