 Thread: Converting an array of elements containing 1's & 0's to binary string

1. Converting an array of elements containing 1's & 0's to binary string

Hi all.

I'm trying to convert a 1D array of 8 elements containing only numbers between 0 and 1 to an 8-bit binary string, but I just can't get it right. I'm hoping someone here knows how to do this..

I've tried things like..

- set alterable string to (bin\$(2 pow(valueAtXY("array", 7,0)*7) ) + (2 pow(valueAtXY("array", 6,0)*6) )+ (2 pow(valueAtXY("array", 5,0)*5) ) +
[...etc...]
(2 pow(valueAtXY("array", 1,0)*1) )+(2 pow(valueAtXY("array", 0,0)*0) )

But this obviously gives me incorrect values. Does anyone know the correct formula? Ideally I want to avoid looping through elements.

Any kind of help or insight would be much appreciated.  Reply With Quote

2. Never mind, I'm an idiot.

This was the solution...

Bin\$(( ( ( ValueAtXY( "BIT_ARRAY", 7, 0 ) * 128 ) ) + ( ( ValueAtXY( "BIT_ARRAY", 6, 0 ) * 64 ) ) + ( ( ValueAtXY( "BIT_ARRAY", 5, 0 ) * 32 ) ) + ( ( ValueAtXY( "BIT_ARRAY", 4, 0 ) * 16 ) ) + ( ( ValueAtXY( "BIT_ARRAY", 3, 0 ) * 8 ) ) + ( ( ValueAtXY( "BIT_ARRAY", 2, 0 ) * 4 ) ) + ( ( ValueAtXY( "BIT_ARRAY", 1, 0 ) * 2 ) ) + ( ( ValueAtXY( "BIT_ARRAY", 0, 0 ) * 1 ) ) ))  Reply With Quote Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•