# Thread: Is this considered an AND operation?

1. ## 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;
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.

2. 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).

3. For the record, yes, it is an 'and' symbol. It is a bitwise and, and not a logical and.

Quzah.

4. 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!

5. & is the bitwise AND operator.

In other words:
status1 would contain the lower 7 bits of inp(UUT_baseaddr+1)

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.

6. 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.

7. 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.

8. Yep, that's what the & operator is primarily used for.

9. Go here for a good tutorial.

Quzah.

10. Thanks so much!! It is working great now. Your response was exact!!

Thanks again!!