03-22-2025, 10:19 AM
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?
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)