Link to home
Start Free TrialLog in
Avatar of JHBrother
JHBrother

asked on

What does "If(!(CurValue & 0X8000))" mean

Should be a easy 20 points for you.
Can someone tell me what it means in english?
ASKER CERTIFIED SOLUTION
Avatar of nietod
nietod

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of nietod
nietod

First of all, I assume you are asking about

If(!(CurValue & 0X8000))

not

&If(!(CurValue & 0X8000))&

 I think there are two extra &"s which I beleive are a typo, or are an HTML artifact.  If I am wrong, post a longer example  (for text from before and after).

starting inside and working out (which is how it will be executed)  

The compiler does a bitwise and of CurVal 0x8000.  Assuming this is 32 bit code, 0X8000 is a value with the high bit set.  So this code returns a non-zero value (true) if  CurValue's high bit is set.  It returns a zero value (false) if CurValue's high bit is clear.

This value is inside "!( )" so the compiler toggles it from true to false.  Thus now we have true if CurValue's high bit is clear.  False if it is set.

This goes into the if().  If you are not familiar with if's, then the "if statements" will execute if CurValue's high bit is clear.  The "else statements" (if there are any) will execute if CurValue's high bit is set.

Avatar of JHBrother

ASKER

Thank you.
This is what the program looks like (in C++)
currVal = GetRecInt()
Trans = (Double)MASK(CurVal)- (double)Dark
If (!(CurrVal& 0X8000))
      Trans /=Factor;

CurrVal is of two bytes (16 bits)

That's what i thought it would look like and it is what I described.  (Your title has extra &'s, or at least it does on my browser, and that threw me a little.

I said 32 bits in my answer, but I meant 16 bits.  Force of habit.  Haven't dealt with 16bit code in over a year.

Does this make sense to you now?