3

I'm running into a problem where VB6 gives me an overflow. I'm using bitwise operations to find the state of an individual bit, but the statement in particular is the final line of:

Dim a As Double Dim b As Double Dim c As Double a = 2 ^ 31 b = 0 c = b And a

And the error occurs on that last line, an overflow. I'm under the impression the And operator is limited to 4 bytes (long in VB6) and therefore overflows with

a = 2 ^ 31

which is greater than the upper limit of a long. Can someone confirm/clarify/solve this problem? Again, I just need to find the state of an individual bit. (This also occurs if I make a, b, and c Currency, which is also 8 bytes but stored as an integer types. I need 44 bits, so I defaulted to the 8-byte data types)

(I'm new to bit manipulation and VB in general, and StackOverflow as well so forgive any mistakes I may have made)

YogrtMan
  • 51
  • 3
  • 6
    These operators (`And`, `Or`, etc.) are not defined for anything but Long, Integer, and Byte. So the compiler is trying to guess what you meant and tries inserting CLng() conversion calls. Those conversions are where the overflow exceptions occur. – Bob77 Jul 26 '16 at 01:07
  • VB6 isn't the language I'd pick for new development of bit-manipulation code (though I've never seen another language with a Bitwise Implication operator). It's not clear to me what you're actually trying to accomplish here, as bitwise operations on floating point values are rarely useful. Are you just trying to store 44 boolean values in less memory? Are you trying to interoperate with some other system that uses bit flags? Are you actually trying to understand how VB6 stores Double values? –  Jul 26 '16 at 13:24
  • Thanks for the responses. I didn't use a double for a floating-point value so much as for the 8 bytes of storage. Bob, that's what I expected. Oh well :/ I worked around it by using an array of six Bytes instead. The alternative to bit manipulation was upwards of 100 booleans per entry in a database-type program, so I stuck with bits xD – YogrtMan Jul 26 '16 at 18:55
  • Will add extra 5cents to the statements above. [VB6 doesn't support unsigned integers](https://stackoverflow.com/questions/4875212/does-vb6-support-unsigned-data-types) so the bitwise operations may fail on the first bit set to 1 (i.e. numbers higher than `2147483647`). Wouldn't it be much easier to have an array/type of Booleans instead? – TAbdiukov Dec 03 '19 at 15:01

0 Answers0