Moving 1 BIT from a variable to another
TC
Posts: 1,019
Hello all,
I am working a on a project where I have to split variables into bits, and but it into another variable. I need to take the BYTE data in a variable, split it into BITS, then put each bit into other variables.
I'll give you an idea... (I hope)
I need the output to be
I hope this makes sense, and I can bet there is a way to do it, but I don't know how or even where to start to figure it out.
Thanks
TC
I am working a on a project where I have to split variables into bits, and but it into another variable. I need to take the BYTE data in a variable, split it into BITS, then put each bit into other variables.
I'll give you an idea... (I hope)
VAR IN_DATA[10] OUT_DATA[7] IN_DATA[0] := %01100000 IN_DATA[1] := %11010000 IN_DATA[2] := %00000000 IN_DATA[3] := %11111111 IN_DATA[4] := %10101010 IN_DATA[5] := %01010101 IN_DATA[6] := %00001111 IN_DATA[7] := %11110000 IN_DATA[8] := %11001100 IN_DATA[9] := %00110011
I need the output to be
OUT_DATA[0] = %0101100110 ' BIT 7 OF EACH "IN_DATA" OUT_DATA[1] = %1101010110 ' BIT 6 OF EACH "IN_DATA" OUT_DATA[2] = %1001100101 ' BIT 5 OF EACH "IN_DATA"
I hope this makes sense, and I can bet there is a way to do it, but I don't know how or even where to start to figure it out.
Thanks
TC
Comments
If you want to find out if a certain bit is high, you can test by
To extend this:
I don't know why I didn't think of AND or OR. That might just work, I will have to see if I can figure something out.
Thank you
Thanks Mike,
I only care about bits 0 to 9 of DATA_OUTPUT. Taking your code and changing the names, I have this
I have not tested it yet, but I am working on it right now.
Thank you