-SOLVED - Bytes problem
grasshopper
Posts: 438
If I have 8 bytes and all I am interested in is the last bit of each how would I put that all the bits in another byte. For example
Var
Byte X1,X2,X3,X4,X5,X6,X7,X8 ,Total
X1 := %0001
x2 := %0000
x3 := %0001
X4 := %0001
x5 := %0000
x6 := %0001
X7 := %0001
x8 := %0001
Total would equal %10110111
Could I bit shift and OR them some how?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit my site -> [url=Http://www.rawcircuits.com]www.rawcircuits.com[/url]
Post Edited (grasshopper) : 3/20/2009 4:24:07 PM GMT
Var
Byte X1,X2,X3,X4,X5,X6,X7,X8 ,Total
X1 := %0001
x2 := %0000
x3 := %0001
X4 := %0001
x5 := %0000
x6 := %0001
X7 := %0001
x8 := %0001
Total would equal %10110111
Could I bit shift and OR them some how?
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Visit my site -> [url=Http://www.rawcircuits.com]www.rawcircuits.com[/url]
Post Edited (grasshopper) : 3/20/2009 4:24:07 PM GMT
Comments
careful there; your solution only works if you can guarantee that all the other bits (ie except for the least significant bit) of X1 to X8 are zero;
otherwise the output will be unpredictable
If the upper bits of X1 .. X8 can also contain other data, then you have to mask out everything but the lsb, eg
Total := (x1 & 1) << 7 | (x2 & 1) << 6 | (x3 & 1) << 5 | (x4 & 1) << 4 | (x5 & 1) << 3 | (X6 & 1) << 2 | (x7 & 1) << 1 | (X8 & 1) << 0
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
---
Jo