• Post Reply Bookmark Topic Watch Topic
  • New Topic

What does this hex (?) value mean / do??  RSS feed

 
Gail Schlentz
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I've been tasked with commenting some old code on our project, and am having trouble finding out what the following "if" condition is doing. I've figured out that the hex number there equates to decimal -32768, and I have a pretty good general idea of how the '&' operator works, but it's just not coming together for me. Any ideas?

 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Imagine "FFFF8000" as a binary number: it's seventeen ones followed by fifteen zeros. The expression "if((0xFFFF8000 & status) != 0)" means "if one or more of the first seventeen bits of 'status' are set to one..." This kind of code is generally used to pack a whole bunch of boolean flags into one int, to save space.
 
Gail Schlentz
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Wow. You're awesome. Thank you very much!!! OK if I include part of your explanation in the code comments?
 
Ernest Friedman-Hill
author and iconoclast
Sheriff
Posts: 24215
37
Chrome Eclipse IDE Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Sure!
 
Gail Schlentz
Ranch Hand
Posts: 634
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
JavaRanch should give you a raise!!
 
Ken Blair
Ranch Hand
Posts: 1078
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree. I think they can afford to give him a 1000% raise.
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!