Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

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

 
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
Marshal
Pie
Posts: 24208
35
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
Marshal
Pie
Posts: 24208
35
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic