How do I represent a byte array position value into binary string?
Don M
Posts: 1,652
Let's say I have a byte array of 16 bytes and also a 2 byte array. If any one of those 16 bytes is an $FF then I would want the corresponding position of one of the bits set in the 2 byte array. I know it's hard to explain.
Byte array of 16: $00, $03, $05, $FD, $FF, $FF, $EE, $FF, $09, $00, $03, $05, $FD, $FF, $50, $09
then the 2 byte array would look like this in binary: 0000 1101 0000 01000
So how do I go about testing the bytes in the array and then setting a bit in the 2 byte array (or 1 word) if it's an $FF?
Comments
In spin (probably much more efficient ways to do this, but this explains how):
dgately
Thanks. Much appreciated.
One more question.. leaving the dataBytes in the order they are in your example how do I reverse the order in the bitArray so it comes out 0010000010110000 ? I tried reversing the "repeat idx from 15 to 0" to "0 to 15" but it was still the same.
Figured it out. Changed mask := 1 << (15 - idx) to mask := 1 << ( idx)
Thanks.
Welcome...