# Thread: A Bit of Set Theory Doesn't Hurt... (2003)

1. ## A Bit of Set Theory Doesn't Hurt... (2003)

In the VBA Editor's Immediate window, if I type
? 3 AND 4
I get 0
but if I type
? -3 AND -4
I get -4
What's the rationale behind it?

2. ## Re: A Bit of Set Theory Doesn't Hurt... (2003)

Look at the values in hex:
-4 is FB which is 1111 1011 in binary
-3 is FC which is 1111 1100 in binary
So if you and them you get 1111 1000 whic is -4

3. ## Re: A Bit of Set Theory Doesn't Hurt... (2003)

Thanks Pat, if, in the Immediate window, I type
?Hex(-3) I get
FFFD
?Hex(-4)
I get
FFFC

4. ## Re: A Bit of Set Theory Doesn't Hurt... (2003)

Decimal -3 = hexadecimal FFFD = binary 1111 1111 1111 1101
Decimal -4 = hexadecimal FFFC = binary 1111 1111 1111 1100

The rules for binary And are:
1 And 1 = 1
1 And 0 = 0
0 And 1 = 0
0 And 0 = 0

So decimal -3 And -4 = hexadecimal FFFD And FFFC = binary 1111 1111 1111 1101 And 1111 1111 1111 1100 = 1111 1111 1111 1100 = hexadecimal FFFC = decimal -4

5. ## Re: A Bit of Set Theory Doesn't Hurt... (2003)

Thank you Hans, what part of the hexadecimal notation accounts for the negative sign?

6. ## Re: A Bit of Set Theory Doesn't Hurt... (2003)

The first bit in the number indicates negativity, i.e. if the hexadecimal notation starts with 8, 9, A, B, C, D, E or F, the number is negative.

#### Posting Permissions

• You may not post new threads
• You may not post replies
• You may not post attachments
• You may not edit your posts
•