0

I am trying to create ARGB pixel, I have seen this example:

int createPixel(int r, int g, int b, int a) 
{
 return (a<<24) | (r<<16) | (g<<8) | (b<<0);
}

For understanding I would like get answers to this questions:

  1. What am getting as result (return)?
  2. What is << means?
  3. If value of each color is 255, so for RED 16 is 255 and 23 is 0?
Cœur
  • 37,241
  • 25
  • 195
  • 267
Dim
  • 4,527
  • 15
  • 80
  • 139

1 Answers1

2

<< is binary shift left, this means a will be shifted 24 bits to the left, red 16,... you get an 4byte integer as result, first byte is a (because shifted 24 bits (3Bytes) to the left), second byte is r, third is g, fourth b.

resulting 0xaarrggbb

example input (255,255,0,16) returns 0xFFFF000F

0x stands for "in hex format"

| is a bitwise or.

bbuecherl
  • 1,609
  • 12
  • 20