Solved

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

Posted on 1998-03-03
Medium Priority
332 Views
Should be a easy 20 points for you.
Can someone tell me what it means in english?
0
Question by:JHBrother
• 3

LVL 22

Accepted Solution

nietod earned 80 total points
ID: 1182964
0

LVL 22

Expert Comment

ID: 1182965

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.

0

Author Comment

ID: 1182966
Thank you.
This is what the program looks like (in C++)
currVal = GetRecInt()
If (!(CurrVal& 0X8000))
Trans /=Factor;

CurrVal is of two bytes (16 bits)

0

LVL 22

Expert Comment

ID: 1182967
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?
0

## Featured Post

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article's goal is to present you with an easy to use XML wrapper for C++ and also present some interesting techniques that you might use with MS C++. The reason I built this class is to ease the pain of using XML files with C++, since there is…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
###### Suggested Courses
Course of the Month17 days, 7 hours left to enroll