Question: I'm porting some C++ code to Actionscript 3 and just had a small question I'm confused about.

In one function, one of the parameters is `int* myPtr`. myPtr is the address of an element of a 2D-Array, `&my2DArray[x][y]`. x and y are also parameters of the function. I'm just a little bit confused with what is being accessed when the code accesses, for example, `myPtr[1]`. I think this would be the next element in `my2dArray`, but I'm not sure if this would be `my2DArray[x+1][y]` or `my2DArray[x][y+1]`. Thanks for any help.

Additional info:
my2DArray is created by: 

```
//initPtr is a int*, auxPtr is a int*, as is temp1
initPtr = (unsigned int *)NewPtr(
      sizeof(unsigned int) *
      X * Y);
  }

  auxPtr = initPtr ;

  for (i = 0; i < X; i++) {
    temp1 = auxPtr + i * Y;
    my2DArray[i] = (short *)temp1;
  } 

unsigned char* NewPtr(
  int size)
{
  return ((unsigned char*)calloc(size, sizeof(unsigned char)));
}

```

Answer: 
To dive into fundamentals:

```
public static String binaryAddition(String s1, String s2) {
    if (s1 == null || s2 == null) return "";
    int first = s1.length() - 1;
    int second = s2.length() - 1;
    StringBuilder sb = new StringBuilder();
    int carry = 0;
    while (first >= 0 || second >= 0) {
        int sum = carry;
        if (first >= 0) {
            sum += s1.charAt(first) - '0';
            first--;
        }
        if (second >= 0) {
            sum += s2.charAt(second) - '0';
            second--;
        }
        carry = sum >> 1;
        sum = sum & 1;
        sb.append(sum == 0 ? '0' : '1');
    }
    if (carry > 0)
        sb.append('1');

    sb.reverse();
    return String.valueOf(sb);
}

```
The idea is same as discussed in few of the answers, but this one is a much shorter and easier to understand solution (steps are commented).

```
// Handles numbers which are way bigger.
public String addBinary(String a, String b) {
    StringBuilder sb = new StringBuilder();
    int i = a.length() - 1; 
    int j = b.length() -1;
    int carry = 0;
    while (i >= 0 || j >= 0) {
        int sum = carry;
        if (j >= 0) { sum += b.charAt(j--) - '0' };
        if (i >= 0) { sum += a.charAt(i--) - '0' };

        // Added number can be only 0 or 1
        sb.append(sum % 2);

        // Get the carry.
        carry = sum / 2;
    }

    if (carry != 0) { sb.append(carry); }

    // First reverse and then return.
    return sb.reverse().toString();
}

```