can someone explain this to me?
BlitzPlus Forums/BlitzPlus Beginners Area/can someone explain this to me?
| ||
I was looking though so code I downloaded and I came across a variable assignment that I don't understand how it works? RGB = (R Shl 16) Or (G Shl 8) Or B I don't understand the use of the Or statements? In a if then, if I understand it right, it compares each argument and returns true if one or more is true. example if a=b or b=c then doThis this does something like this when running, evaluate argument a=b, equals true or false evaluate argument b=c, equals true or false then if either one of these arguments is true process the doThis code. right? So how is it used in the variable assignment? Thanks, CTP |
| ||
I believe (although I am not certain) that it is doing a binary or. Basically this compares two binary numbers, and the result is another binary number. What an or does is it goes through each bit in two numbers and checks to see if one or both bits are a 1. If so, it puts 1 in the new numbers but position, if not, zero. It's good to use for 'turning bits on'. A visual representation is best: 5 or 12 00000101 ==> binary 5 or 00001100 ==> binary 12 = 00001101 ==> binary 13 That's a binary or. I would assume that this is what it is doing but again, I am not sure because I do not have the context of the code. |
| ||
This is a bitwise-OR. example, for purple: R = 255 (FF) (11111111) G = 0 (00) (00000000) B = 255 (FF) (00000000) SHL 16 means to shift the bit pattern 16 places to the left. R SHL 16 turns into: 11111111 00000000 00000000 G SHL 8 turns into: 00000000 00000000 00000000 B is unmodified: 00000000 00000000 11111111 The bitwise OR overlays these three strings, and sets it to '1' if at least one of them has a 1 in that spot. The end result: 11111111 00000000 11111111 (or: FF00FF in hex = purple) |
| ||
hmmm I had always wondered about that... good to know |
| ||
Bitwise, not binary, silly me. |