Results 1 to 6 of 6
  1. #1
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. #2
    Platinum Lounger
    Join Date
    Dec 2001
    Location
    Melbourne, Australia
    Posts
    4,594
    Thanks
    0
    Thanked 27 Times in 27 Posts

    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. #3
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. #4
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    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. #5
    Bronze Lounger
    Join Date
    Jan 2001
    Location
    Alzano Lombardo, Italy
    Posts
    1,483
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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. #6
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    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
  •