Those are Bitwise Operators. https://developer.mozilla.org/en/JavaScript/Reference/Operators/Bitwise_Operators
"a << b" means shift "a" left by "b" bits. So, "0010 << 2" would be "1000". And a single pipe is the bitwise "or" operator. So, "0010 | 1000" would be "1010". Of course, if you're not used to binary arithmetic, that stuff may be a little bit (ha!) meaningless. Putting it together, what getRGB does is take 3 8-bit component colors and returns a 32-bit representation of the color. Let's say r = 255 = 0xFF = 1111 1111 g = 100 = 0x65 = 0110 0101 b = 1 = 0x01 = 0000 0001 r << 24 = 1111 1111 0000 0000 0000 0000 0000 0000 g << 16 = 0000 0000 0110 0101 0000 0000 0000 0000 and "or"ing them together gets you 1111 1111 0110 0101 0000 0000 0000 0001 That said, am I reading this to mean that a(alpha) is stored between g and b? _jason On Wed, Nov 2, 2011 at 11:54 AM, Matthew Bramer <remym...@gmail.com> wrote: > I was looking at GitHub at some source code: > https://github.com/mbebenita/Broadway/blob/master/Play/play.js > > and I found this function: > > function getRGB(r, g, b) { > return r << 24 | g << 16 | b; > } > I've never used these expressions before and am having difficulty finding > information about them. Can anyone tell me what these are called and why I > would ever use them? I'm confused over the "<<" syntax. > > Thanks, > Matt > > -- > To view archived discussions from the original JSMentors Mailman list: > http://www.mail-archive.com/jsmentors@jsmentors.com/ > > To search via a non-Google archive, visit here: > http://www.mail-archive.com/jsmentors@googlegroups.com/ > > To unsubscribe from this group, send email to > jsmentors+unsubscr...@googlegroups.com > -- To view archived discussions from the original JSMentors Mailman list: http://www.mail-archive.com/jsmentors@jsmentors.com/ To search via a non-Google archive, visit here: http://www.mail-archive.com/jsmentors@googlegroups.com/ To unsubscribe from this group, send email to jsmentors+unsubscr...@googlegroups.com