# Is this considered an AND operation?

• 07-22-2002
Unregistered
Is this considered an AND operation?
I am a super newbie to C, but have 3 years experience with VB. I am converting a C program to VB and have run into something I am not familiar with. Here is the code. My question is below the code:

Code:

```status1 = inp(UUT_baseaddr+1) & 0x7F; status2 = inp(UUT_baseaddr) & 0xFF;```
After the call to the 'inp' routine there is the '&' symbol and a HEX value. They come out to be 127 and 255.

What exactly is that doing?

Is is concactenating 127 and 255 to the result from 'inp'?

When I use this command in VB:

Code:

`status1 = inp(UUT_baseaddr+1) & 127`
I get the response from inp as 255, but then VB concactenates the 127 to the end of the response and I end up with

"255127"

Which I don't think it is correct.

Any help or tips is greatly appreciated. I am a C newbie so your comments are greatly appreciated. :)
• 07-22-2002
gabulldog
The hex values are masks, forcing the values to 0 in case of FF and 128 in the case of 7F. (Provided the values are bytes).
• 07-22-2002
quzah
For the record, yes, it is an 'and' symbol. It is a bitwise and, and not a logical and.

Quzah.
• 07-22-2002
mikef
I see. So if it were to return 255 or 127, then the program would make them equal to zero?

Thanks again for your expertise and help!

:)
• 07-22-2002
Cshot
& is the bitwise AND operator.

In other words:
status1 = inp(UUT_baseaddr+1) & 0x7F;
status1 would contain the lower 7 bits of inp(UUT_baseaddr+1)

status2 = inp(UUT_baseaddr) & 0xFF;
status2 would contain the lower 8 bits of inp(UUT_baseaddr)

I'm assuming your result is a 16-bit number with status1 being the most significant. Therefore youre result would be the lower 15 bits.
• 07-22-2002
Cshot
Quote:

I see. So if it were to return 255 or 127, then the program would make them equal to zero?
NO it would not because

255 which is:
0xFF
AND
0xFF
would result in 0xFF

If your function returned 0xFF and you & with 0x7F, you would get 0x7F. Dunno where you guys are getting the zero from.
• 07-22-2002
mikef
Ok. I was a little confused at first.

By using the '&' I am specifying which bits I want to read from the result and assigning them to the variable status1 or status2?

Am I on the right track here??

Thanks to everyone for your help so far. :)
• 07-22-2002
Cshot
Yep, that's what the & operator is primarily used for.
• 07-22-2002
quzah
Go here for a good tutorial.

Quzah.
• 07-22-2002
mikef
Thanks so much!! It is working great now. Your response was exact!!

Thanks again!!

:) :) :) :) :) :) :)