Results 1 to 5 of 5
  1. #1
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    logical Or versus arithmetic Add (word2000 et al.)

    I have two functions, each function takes a logical mask where bits represent choices.
    The hardware function tests perfectly with 11 items, all bits turned on, hence 2047.
    The software function tests perfectly with 20 items, all bits turned on, hence 2147483647.
    The combined text (below) fails (overflow) with "strSignature(2147483647 <font color=red>+</font color=red> 2047, "*")" but succeeds with strSignature(2147483647 <font color=448800>Or</font color=448800> 2047, "*")
    <pre>Public Function strSignature(lngMask As Long, strDelimiter As String) As String
    ''' The signature is a combination of Application identifier; Hardware; Software
    strSignature = H.strSignatureHardware(lngMask, strDelimiter) & S.strSignatureSoftware(lngMask, strDelimiter)
    End Function
    Sub TESTstrSignature()
    MsgBox strSignature(2147483647 Or 2047, "*")
    End Sub
    </pre>


  2. #2
    Plutonium Lounger
    Join Date
    Mar 2002
    Posts
    84,353
    Thanks
    0
    Thanked 29 Times in 29 Posts

    Re: logical Or versus arithmetic Add (word2000 et al.)

    2147483647 is the largest positive number that can be stored in a Long, so 2147483647 + 2047 causes an overflow. The 'Or' operator doesn't add, it operates bitwise, so 2147483647 Or 2047 doesn't cause a problem.

  3. #3
    Star Lounger
    Join Date
    Jul 2006
    Location
    Colorado, USA
    Posts
    55
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: logical Or versus arithmetic Add (word2000 et al.)

    20 items would make 1048575, not 2147483647. 2147483647 is for 31 items, and is also the max size for an unsigned long integer. I think that what you may want is the 1048575 shifted over 11 bits to the left and then OR'd with the remaining 11. This would give 2147481600 (=1048575*2048) for the first 20 bits OR'd with the 2047. This would then give 2147483647 at max.

  4. #4
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: logical Or versus arithmetic Add (word2000 et

    > you may want is the 1048575 shifted over 11 bits
    Absolutely right.
    My test was faulty in that I had all 31 bits set, and ORed them needlessly with the lower 11 bits. The end result for my test was the same - I received all 31 characteristics.
    A test expression of "2147481600 OR 2047" is much clearer.

  5. #5
    Platinum Lounger
    Join Date
    Feb 2001
    Location
    Yilgarn region of Toronto, Ontario
    Posts
    5,453
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Re: logical Or versus arithmetic Add (word2000 et

    > The 'Or' operator doesn't add, it operates bitwise,
    Right! That's why I shifted (ouch!) my approach.
    It is a coincidence that I ended up with 20+11 characteristics. Shades of IBM/360 there .....

Posting Permissions

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