Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Endian swapping in QB64pe
#5
For an explanation of the issue you're seeing, (so you can account for it elsewhere in your code), see this:

Code: (Select All)
Print Hex$(&HFFFFFFFF And &HFF)
Print Hex$(&HFFFFFFFF And &HFFFF)
Print Hex$(&HFFFFFFFF And &HFFFFFFFF)
Print
Print &HFF
Print &HFFFF
Print &HFFFFFFFF
Print
Print &HFF~%%
Print &HFFFF~%
Print &HFFFFFFFF~&


Notice how the &H value changes on you? That's because QB64 and basic back in the day, didn't have UNSIGNED values, and also because they wanted to save as much precious memory as possible.

&HH was... an INTEGER, as there was no _BYTE type in QB45. Thus, it represented 255.
&HHHH was... an INTEGER, as integers are 2 bytes and that was the smallest size that could represent those hex digits. As an integer, that made its value -1.
&HHHHHHHH was... an LONG. 4 bytes to hold those 8 hex values. In a signed long, that also made the value -1.

So.... when you AND a value with -1, is that AND with a long or an integer or ????

You run into issues. (As you both have noticed.)



Solution?

Take that ambiguity out of your &H type.

IF &HFF is *supposed* to be a LONG, then mark it as one: &HFF&
IF &HFF is *supposed* to be an _INTEGER64, then mark it as one: &HFF&&

Those suffixes there on the end of that &H value is *essential* for what you're doing to work without issues for you. Else you're mixing integers with longs with int64s and... You get FEFOFLOPOP00PS
Reply


Messages In This Thread
Endian swapping in QB64pe - by tantalus - 03-22-2025, 10:19 AM
RE: Endian swapping in QB64pe - by Petr - 03-22-2025, 02:54 PM
RE: Endian swapping in QB64pe - by tantalus - 03-22-2025, 03:10 PM
RE: Endian swapping in QB64pe - by SMcNeill - 03-22-2025, 03:25 PM
RE: Endian swapping in QB64pe - by tantalus - 03-22-2025, 03:47 PM
RE: Endian swapping in QB64pe - by DSMan195276 - 03-22-2025, 04:31 PM
RE: Endian swapping in QB64pe - by SMcNeill - 03-22-2025, 03:42 PM
RE: Endian swapping in QB64pe - by SMcNeill - 03-22-2025, 04:01 PM
RE: Endian swapping in QB64pe - by Petr - 03-22-2025, 05:03 PM



Users browsing this thread: 1 Guest(s)