Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Endian swapping in QB64pe
#1
Both of these routines work if I implement them in C as an external library or use the bswap_32/bswap_64 libc functions.

They also happen to work in other BASIC's like FreeBASIC, BBC BASIC (SDL & Windows) and even the 32bit routine works in GFA BASIC on the Atari ST.

Looking at the CPP code QB64pe uses for _SHL/_SHR, it "should" work!

Is it QB64pe or me?

Code: (Select All)

' 64 Bit endian swap, should print DEADBEEFCAFEF00D
' But instead prints...            FEFFFEEFCAFEF00D
DIM SHARED AS _UNSIGNED _INTEGER64 rax, rdx
rdx = &H0DF0FECAEFBEADDE
rax = _SHR((rdx AND &HFF00000000000000), 56) OR _
      _SHR((rdx AND &H00FF000000000000), 40) OR _
      _SHR((rdx AND &H0000FF0000000000), 24) OR _
      _SHR((rdx AND &H000000FF00000000),  8) OR _
      _SHL((rdx AND &H00000000FF000000),  8) OR _
      _SHL((rdx AND &H0000000000FF0000), 24) OR _
      _SHL((rdx AND &H000000000000FF00), 40) OR _
      _SHL((rdx AND &H00000000000000FF), 56)
PRINT HEX$(rax)

'32 Bit endian swap, should print DEADBEEF
'But instead prints...            FEADBEEF
DIM SHARED AS _UNSIGNED LONG eax, edx
edx = &HEFBEADDE
eax = _SHR((edx AND &HFF000000), 24) OR _
      _SHR((edx AND &H00FF0000),  8) OR _
      _SHL((edx AND &H0000FF00),  8) OR _
      _SHL((edx AND &H000000FF), 24)
PRINT HEX$(eax)
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)