How do I handle "bitmasks"-arrays of an image? Too long values!

Hey I got this code that checks two images that overlap each other if any pixels are transparent, anyway; I made an array like this and I got it to work:

The image is 8x8 so I make the array like this:

public long[] getArray(){
		long[] array = new long[8];
		String s = null;
		
		for(int i = 0; i<8; i++){
			for(int z = 0; z <8; z++){
				String s2; 
				if(image.getRGB(z, i)==0){ s2 = "0";}
				else s2 = "1";
				
				if(s == null) {s = s2;}
				else s+=s2;	
			}
			array[i] = Long.parseLong(s);
			s = null;
		}
		return array;
	}

As you see, the result would be a 8 long array with each cell representing a whole row of the image so for example, the value of array[0] would represent a whole row like:
111000

But here’s the problem… For this to work, the image has to be less wide than 20 pixels or else I get a NumberFormatException, in other words the whole combination of
1s and 0s becomes too long.

So, how are you actually supposed to handle these bitmask arrays since a mere 20 pixels is very restrictive!

Let’s ignore that the use of Strings for this is rather inefficient, as ‘it works’…

You should interpret the string as binary, so ‘10’ wouldn’t be ten, but two.

Long.parseLong(s, 2 /* radix */);

Oh I see, such an easy solution! Thanks a lot!!!

However, if still interested, could you briefly just say what the more efficient method is? Instead of strings that is! Granted, I’m still at the level where optimization is irrelevant but it’s always fun to know!

Check out java.util.BitSet.