Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Sample program using the new _Files$ function
#23
&B1111111111111111 is an unsuffixed value, so QB64 is going to try and use the same logic that QB45 used on this -- convert it to the smallest variable type that would hold this value.

Now, this value in QB45 would be -1, as it'd store those 16-bits in an integer.   Don't believe it?  Just try a simple:  PRINT &B1111111111111111

Now, once you have a value of -1, you assign that value to b, in the code:

b = &B1111111111111111
b = -1

Since b is 64 unsigned-bits, the value of -1 is &B1111111111111111111111111111111111111111111111111111111111111111, or in hex, it's the value you see on your screen: FFFFFFFFFFFFFFFF

So how to fix this, to make certain that the &B value doesn't become -1?

SUFFIX IT!!!!

Code: (Select All)
DIM b AS _UNSIGNED _BIT * 64
b = &B1111
PRINT HEX$(b)
b = &B11111111
PRINT HEX$(b)
b = &B111111111111
PRINT HEX$(b)
b = &B1111111111111111
PRINT b, HEX$(b)
b = &B1111111111111111~%
PRINT b, HEX$(b)

And that's all there is to make these type of issues go away.   If you want an unsigned integer64, then use the suffix on &B to make certain that you tell it to return you an unsigned integer64 value.  That intermediate math is what's giving you predictable, but unexpected for you, results. Wink
Reply


Messages In This Thread
RE: Sample program using the new _Files$ function - by SMcNeill - 02-14-2024, 10:16 AM



Users browsing this thread: 2 Guest(s)