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

Popular posts from this blog

Failed to execute goal org.apache.maven.plugins:maven-surefire-plugin:2.12:test (default-test) on project.Error occurred in starting fork -

windows - Debug iNetMgr.exe unhandle exception System.Management.Automation.CmdletInvocationException -

configurationsection - activeMq-5.13.3 setup configurations for wildfly 10.0.0 -