Guys,
I am in need of help of how to combine three 4 bit pieces of data read in by a function to one consecutive 12bit piece of data.
the data would come in as
variable0=0010
variable1=1111
variable2=0101
How would I code the program so as once the seperate variables are obtained I can produce
variablecombined=010111110010
Any help would be much appreciated.
Regards,
Austfreddo
This is where the bit-shift operators come in handy. You'll need left-shift: <<.
Start with a zero result, shift each piece into place, and add it into the result.
Hope this helps.
So would I be correct in stating that Var0 would not be shifted, var1, left shift 4 bits, var2 left shift 8 bits?
Would you care to provide a quick example Duoas? It would help out quite alot.
Cheers,
Brett
Actually you have it exactly.
int two_hundred_fifty_six = 1 << 8;