Solved

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

Posted on 1998-03-03
4
286 Views
Last Modified: 2011-10-03
Should be a easy 20 points for you.
Can someone tell me what it means in english?
0
Comment
Question by:JHBrother
  • 3
4 Comments
 
LVL 22

Accepted Solution

by:
nietod earned 20 total points
ID: 1182964
Answer coming.
0
 
LVL 22

Expert Comment

by:nietod
ID: 1182965
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.

0
 

Author Comment

by:JHBrother
ID: 1182966
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)

0
 
LVL 22

Expert Comment

by:nietod
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

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

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

Article by: SunnyDark
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…
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
The viewer will learn how to pass data into a function in C++. This is one step further in using functions. Instead of only printing text onto the console, the function will be able to perform calculations with argumentents given by the user.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question