Solved

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

Posted on 1998-03-03
4
268 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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
Introduction This article is a continuation of the C/C++ Visual Studio Express debugger series. Part 1 provided a quick start guide in using the debugger. Part 2 focused on additional topics in breakpoints. As your assignments become a little more …
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 user default arguments when defining functions. This method of defining functions will be contrasted with the non-default-argument of defining functions.

707 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now