I’ve been trying to figure this out for a while, I’ve come to terms with a lot of things thanks to this forum and I always do a good google search before I ask here but they seem to be quiet hard to understand hence asking so if someone could please explain why the bitshift operators are needed in this random pixel generator:
BufferedImage img = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB);
File f = null;
for(int y = 0; y < height; y++) {
for(int x = 0; x < width; x++) {
int a = (int)(Math.random()*256); //alpha
int r = (int)(Math.random()*256); //red
int g = (int)(Math.random()*256); //green
int b = (int)(Math.random()*256); //blue
int p = (a<<24) | (r<<16) | (g<<8) | b; //<<<------HERE
img.setRGB(x, y, p);
}
}
I notice this ususage with a lot of tutorials and its where I’d normally get confused with, what is its purpose? When I took away the operators it was giving me an image of some kind. I know that if the value is 40 in binary it shifts by 1,2,3,4,5,6 along the 010101000(i.e ?40) if this makes sense but what is the purpose here for these RGB values? Thanks