Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
trying to understand bitwise operations
#2
Binary is not a different kind of a number. It is one of ways you can write a number. You can write the same number in decimal, hexadecimal, binary or some other format. In QM you can write numbers in decimal and hexadecimal format. In QM you cannot write numbers in binary format, but you can imagine.

decimal binary
0 00000000
1 00000001
2 00000010
3 00000011
4 00000100
5 00000101
...

Example of 5&3:
decimal binary
5 00000101
&
3 00000011
=
1 00000001

Compare each column. If both numbers contain 1 in the same column, then result will contain 1 in that column. Else result will contain 0 in that column.

------------

if(flags=2) and if(flags&2) are different. if(flags=2) is true only if flags is exactly 2. if(flags&2) is true if flags contains 1 in 2-nd column from the right (because 2 contains 1 in that column). It is true if flags is 2, 3, 6, 7 and so on. if(flags&4) is true if flags contains 1 in 3-rd column from the right (because 4 contains 1 in that column).


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)