• Post Reply Bookmark Topic Watch Topic
  • New Topic

OR | Question  RSS feed

 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Forgive the stupid question. I have some test code:



Why is the number 3 printed?
 
Charlie Goth
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Note to self - read questions properly!
[ July 08, 2004: Message edited by: Charlie Goth ]
 
Charlie Goth
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've just run the code, it printed 1.
 
Gregg Bolinger
Ranch Hand
Posts: 15304
6
Chrome IntelliJ IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Ok, so the | is just adding the numbers together?
 
Charlie Goth
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It 'ors' the two values together at binary level.
0 = 00000000
1 = 00000001
0|1 is the binary value where either (or both) bits in each position are 1, so 0|1 is 00000001.
1|2 would be 00000011.
2|2 would be 00000010.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!