Sample program using the new _Files$ function - Printable Version +- QB64 Phoenix Edition (https://qb64phoenix.com/forum) +-- Forum: QB64 Rising (https://qb64phoenix.com/forum/forumdisplay.php?fid=1) +--- Forum: Code and Stuff (https://qb64phoenix.com/forum/forumdisplay.php?fid=3) +---- Forum: Utilities (https://qb64phoenix.com/forum/forumdisplay.php?fid=8) +---- Thread: Sample program using the new _Files$ function (/showthread.php?tid=2393) |
RE: Sample program using the new _Files$ function - eoredson - 02-14-2024 Is there an error in this code or am I doing something wrong? Code: (Select All) Dim b As _Unsigned _Bit * 64 RE: Sample program using the new _Files$ function - GareBear - 02-14-2024 eoredson, Change 64 in line one to 16. I got 'FFFF' instead of 'FFFFFFFFFFFFFFFF'. Then I changed the 16 to 32 when the limit is reached. When 32 is reached I went to 64. To keep the 16 bit 'F' in line as I go up. With 64 you was having 16 'F' instead of 4 'F'. This is not the easiest thing to grasp. With the changes I made the count goes smoothly up like it should. -GareBear. Code: (Select All) Dim b As _Unsigned _Bit * 16 ' This gives one more 'F'instead of twelve more in line 9. RE: Sample program using the new _Files$ function - SMcNeill - 02-14-2024 &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)
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. RE: Sample program using the new _Files$ function - GareBear - 02-14-2024 SMcNeil, Did I make your sense of getting to the point hurt? You showed me a short cut I did not know about. - GareBear. RE: Sample program using the new _Files$ function - GareBear - 02-14-2024 Correction to previous code, this is better and does the same thing with less. Thank you,SMcNeil! Code: (Select All) Dim b As _Unsigned _Bit * 64 RE: Sample program using the new _Files$ function - SMcNeill - 02-14-2024 @GareBear One thing that you may want to keep in mind is to always use the proper suffix for whatever value you're sing. ~ is UNSIGNED %% iBYTE % is INTEGER & is LONG && is INTEGER64 So ~&& is the suffix for an unsigned integer64. These suffixes should ALWAYS be used with literal values, if you want to make certain you keep the data types correct. For example, 123456789098 can often get turned into a SINGLE value and become 1.23456E12, losing precision. To make certain you retain that proper value, use the number 123456789098&& instead, to force it to be an integer64 instead. -1 is a terrible value to mess things up. As a byte, -1 is represented as &HFF. As an integer, -1 is &HFFFF. As a long, -1 is &HFFFFFFFF. As an integer64, -1 is &HFFFFFFFFFFFFFFFF. When using literal values, or &H, &B, &O -- which are the equivelant to literal values, just in a different base -- one should ALWAYS suffix them, or else they'll end up with unexpected results like what the programs above generate. (Full list of suffixes can be found here: https://qb64phoenix.com/qb64wiki/index.php/TYPE ) RE: Sample program using the new _Files$ function - GareBear - 02-14-2024 Without the SUFFIX, I got the correct result in a potentially confusing long way around. Maybe confusing with more than one variable to 'Dim' where one 'Dim' with the SUFFIX will do getting rid of the -1 and keeping the 0 and 1's unsigned. You probably saw my reasoning behind the long way around (16, 32 and 64). To me it made sense, but it is not Keep It Simple Stupid - KISS. A lot errors in coding can be spotted easier this way. Thank you for your help. RE: Sample program using the new _Files$ function - eoredson - 02-15-2024 Thanks steve! I rewrote the bit assignment with this and it works.. Code: (Select All) Dim b As _Unsigned _Bit * 64 RE: Sample program using the new _Files$ function - eoredson - 02-15-2024 Just to clarify the issue I have done this: Code: (Select All) Dim b As _Unsigned _Bit * 64 RE: Sample program using the new _Files$ function - eoredson - 02-15-2024 Just to add to the confusion: Does C have 128-bit integers? For example, the GCC C compiler 4.6 and later has a 128-bit integer type __int128 for some architectures. GCC and compatible compilers signal the presence of 128-bit arithmetic when the macro __SIZEOF_INT128__ is defined. |