It's like there really are infinite monkeys and they have produced every possible variation



  •  It's only a small thing but I've got to share it with you. I'm currently porting data from an old Access database to a new system that uses SQL Server. I'm going through a table holding a list of educational institutions and some of the fields are typical numeric fields that represent boolean values. For example there is a field that determines whether the institution gives credit. For those institutions that do not give credit we have either a zero or a blank field. For those that do, we have, you guessed it, -1. Yes, that's minus one.

    Is this some sort of legacy thing? Maybe the developer was hoping to preserve 1 for the hardcore cases, the ones that give so much credit you can skip employment altogether and go straight into retirement? I don't know.



  • enum Bool {
        TRUE = -1, // Fixed 7/7/1982: TRUE was evaluating to FALSE
        FALSE,
        FILE_NOT_FOUND
    }
    
    Bool blnSchoolIsNotUnableToGiveCredits;


  • For a value of 1, only one bit is set and the rest are all unset.

    For a value of -1, in two's-complement at least, ALL THE BITS are set.

    Therefore -1 is much trueier than1 is.



  • @Rootbeer said:

    For a value of 1, only one bit is set and the rest are all unset.

    For a value of -1, in two's-complement at least, ALL THE BITS are set.

    Therefore -1 is much trueier than1 is.

    11111111 is not only a negative boolean, it is also called the RadioShack Customer Information Notation (i.e.: what the RadioShack clerks punched in the customer information fields in the POS). Regional variations of this notation include asdfasdf and zzzzzzzz (this last one not to be confused with the industry-standard Deleted Customer Notation such as zzzzzSmith, John).



  • @Speakerphone Dude said:

    (i.e.: what the RadioShack clerks punched in the customer information fields in the POS)
    Why do I immediately think "Piece of Shit" whenever I see the acronym POS.  Especially when used in the same sentence as Radio Shack.



  • Yes, this is standard in Access/Jet.

    Never cared to look into exactly why, but think of it as a one bit signed number. Since the leading bit is always 1, the value is always negative. Hence "-1". Just test for "<> 0" or "=0" instead, to make things clearer. In vba, any non-zero value is "true".


  • Discourse touched me in a no-no place

    @El_Heffe said:

    Why do I immediately think "Piece of Shit" whenever I see the acronym POS.
    Because both expanded acronyms are suitable for certain tills?



  • @El_Heffe said:

    Why do I immediately think "Piece of Shit" whenever I see the acronym POS.
    Our "point of sale" system shares that alternative monicker, too. In fact, the guy who wrote it used it as well.

    He has since left, and now I'm in charge of the POS. Thanks for reminding me and ruining my day.

     



  • @DOA said:

    For those that do, we have, you guessed it, -1. Yes, that's minus one.

    Is this some sort of legacy thing?

    No idea if it still works like this, but it used to be that in Visual Basic (version ≤ 6), False equalled 0 and True equalled −1. Could well be that Access's booleans were related to this, and the values actually entered into the table were True and False even if they're stored as numbers?



  • @Gurth said:

    No idea if it still works like this, but it used to be that in Visual Basic

    I remember QBASIC used -1 for true. It's still correct for most languages: 0 is false and anything else is true.



  • @Rootbeer said:

    For a value of 1, only one bit is set and the rest are all unset.

    For a value of -1, in two's-complement at least, ALL THE BITS are set.

    Therefore -1 is much trueier than1 is.

    You're right.

    1 != 0, and -1 != 0

    but

    (1 & x) != 0 only for x == 1, whereas (-1 & x) != 0 for all x != 0

    and

    1 != ~0, whereas -1 == ~0 (where ~ is the bitwise complement).



  •  Exactly and AFAIK this still is the case for VBA, speak MS Access. So the WTF is VB(A) and Access and not the developer.



  • @beginner_ said:

     Exactly and AFAIK this still is the case for VBA, speak MS Access. So the WTF is VB(A) and Access and not the developer.

    Sorry, why do you think this a WTF? Did you read the posts above?


    As far as I am aware, oldschool BASIC (from which VBA is obviously derived) never had true/false constants, nor boolean variables, and if you used AND, OR or NOT outside of a condition they behaved as bitwise operators; so it followed that if you wanted to pretend that AND, OR and NOT were logical operators then using -1 as true was the best/sanest choice a BASIC programmer had...


    PRINT NOT(0)

    -1

    PRINT NOT(-1)

    0

    PRINT NOT(1)

    -2



  • @nat42 said:

    PRINT NOT(1)

    -2

     

    What happens with NOT(-2) ?

     



  • @dhromed said:

    @nat42 said:

    PRINT NOT(1)

    -2

     

    What happens with NOT(-2) ?

     

    FILE NOT FOUND


  • @dhromed said:

    @nat42 said:

    PRINT NOT(1)

    -2

     

    What happens with NOT(-2) ?

     

    1 » 00000001

    -2 » 11111110

    FILE_NOT_FOUND » 00000002



  • @dhromed said:

    @nat42 said:

    PRINT NOT(1)

    -2

     

    What happens with NOT(-2) ?

     

     

    In an 8 bit representation:

    0000 0010 

    Apply 2's complement algorithm (flip and add 1)

    1111 1101 + 1 =

    1111 1110

    And Not it

    0000 0001 = 1 in base 10

     


     



  • @dhromed said:

    @nat42 said:

    PRINT NOT(1)

    -2

     

    What happens with NOT(-2) ?

    What a stupid question. If you didn't just post that to be a dick then you should drink a shit-tonne of coffee before being allowed near a keyboard again.

     



  • @Severity One said:

    @El_Heffe said:

    Why do I immediately think "Piece of Shit" whenever I see the acronym POS.
    Our "point of sale" system shares that alternative monicker, too. In fact, the guy who wrote it used it as well.

    He has since left, and now I'm in charge of the POS. Thanks for reminding me and ruining my day.

     

    It's perfectly possible to have a POS system that actually is a steaming POS....



  • @MeesterTurner said:

    It's perfectly possible to have a POS system that actually is a steaming POS....
    I thought that was the norm...



  • Ha ha! These POS jokes are delightful! Not at all extremely old and stale and unfunny! Please, gentlemen, continue.



  • @blakeyrat said:

    Ha ha! These POS jokes are delightful! Not at all extremely old and stale and unfunny! Please, gentlemen, continue.

    Yeah! Those jokes are Plain Old Silly.



  • @Speakerphone Dude said:

    Yeah! Those jokes are Plain Old Silly.

    Purile Obligatory Scatology?



  • @rstinejr said:

    @Speakerphone Dude said:
    Yeah! Those jokes are Plain Old Silly.

    Purile Obligatory Scatology?

    Plus One Sadface:

    :(



  • @Xyro said:

    Plus One Sadface

    Wouldn't that be POSF instead of POS?  Or is "sadface" a Possible Orthography Surrogate?



  • IIRC, back when I was programming on the commodore Pet, 'true' was -1 because the only instruction on the 6502 that could jump based on something you just loaded into the accumulator was "CMP", which would jump if the sign bit was set.
    But that was 30 years ago, and a lot of bits have gone under the bridge since then and I could remember it wrong.



  • With you on the "wrong" part. Not so much on the "remember it" part.

    The 6502 CMP instruction does a subtract without carry of the operand from the accumulator and discards the result, modifying only the flag bits: C will be set if the accumulator is equal to or greater (unsigned) than the operand, N will be set the same as bit 7 of the subtraction result, V (overflow) will be set if the subtraction caused a signed overflow (carry from bit 6 to bit 7 didn't match C flag) and Z will be set if the subtraction result was zero (operand and accumulator were equal).

    Unlike the 8080 family but like the 6800 and 68000 families, the 6502 also sets the N and Z flags when a register is loaded from memory. So if you want to branch on a Boolean value in memory location Result, you could do

            LDA Result
            BNE ResultIsTrue
    

    And this works just as well whether your convention for True is 1 or -1.

    The 6502 also has the BIT instruction which does a bitwise AND betweeen the accumulator and the operand and discards the result, setting the Z flag if the result was zero. That instruction also copies bit 7 of the operand to the N flag and bit 6 to the V flag regardless of the AND result. So you can keep several flags inside a single byte and branch on all of them:

            LDA #1
            BIT Flags
            BMI Bit7IsSet
            BVS Bit6IsSet
            BNE Bit0IsSet
    

    There will be a short quiz at the end of today's lesson.



  • As to why True is -1 in Access: it was that way in the original Microsoft BASIC for the 8080, and Microsoft has a thing about backward compatibility. The original rationale may well have had something to do with the fact that MS BASIC did indeed make no distinction between bitwise and logical AND, OR and NOT operators.


Log in to reply