Is it ok to have a boolean field in that uses values 0 for False and -1 for True?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Michael Brown
    New Member
    • Jan 2011
    • 6

    Is it ok to have a boolean field in that uses values 0 for False and -1 for True?

    Hi,

    Stupid Question:
    I have a boolean field in an Access table that uses values 0 for False and -1 for True

    Is this normal? Shouldn't it be 0 and 1?

    I know this isn't really the right place for a question like this but I really like this site!

    Thanks,
    - MB
  • RuralGuy
    Recognized Expert Contributor
    • Oct 2006
    • 375

    #2
    0 and -1 is exactly right!

    Comment

    • Michael Brown
      New Member
      • Jan 2011
      • 6

      #3
      Thanks Doomguy!

      It seemed weird to me because everywhere I looked online made reference to 0 and 1 as the values, couldn't find anything about -1.

      Comment

      • Rabbit
        Recognized Expert MVP
        • Jan 2007
        • 12517

        #4
        Here's why. The Access boolean data type is actually 2 bytes. So it is basically an integer. And VBA doesn't have an unsigned version of integers. So in binary, true is "10000000000000 00" while false is "00000000000000 00". In signed variables, the leftmost bit, signifies the sign. In the case of signed integers, that leftmost 1 means it's a negative number. And the rest of the zeroes means it's the first negative number, ie -1.

        In most other implementations , a boolean is a byte with true being "00000001" and false being "00000000".

        Comment

        • RuralGuy
          Recognized Expert Contributor
          • Oct 2006
          • 375

          #5
          Actually any non zero value would work for a false in VBA unless you use the Boolean NOT. Then the -1 makes all kinds of sense since the bits are 1's it negates quite nicely.

          Comment

          • Rabbit
            Recognized Expert MVP
            • Jan 2007
            • 12517

            #6
            When evaluating true or false that is the case. But when assigning true or false, it's a constant that it assigns.

            Comment

            Working...