03-22-2025, 03:25 PM
I figure it's mainly missing the type symbols and screwing with you with that.
Code: (Select All)
' 64 Bit endian swap, should print DEADBEEFCAFEF00D
' But instead prints... FEFFFEEFCAFEF00D
Dim Shared As _Integer64 rax, rdx
rdx = &H0DF0FECAEFBEADDE&&
Print Hex$(rdx)
Print Hex$(SwapEnd(rdx))
Print Hex$(SwapEnd(SwapEnd(rdx)))
Print
Print "(leading 0 is missing when printed)"
Function SwapEnd~&& (num As _Unsigned _Integer64)
Dim As _Unsigned _Integer64 temp, temp2
temp = _ShL(num And &HFF&&, 56) 'byte #1
temp = temp Or _ShL(num And &HFF00&&, 40) '2
temp = temp Or _ShL(num And &HFF0000&&, 24) '3
temp = temp Or _ShL(num And &HFF000000&&, 8) '4
temp = temp Or _ShR(num And &HFF00000000&&, 8) '5
temp = temp Or _ShR(num And &HFF0000000000&&, 24) '6
temp = temp Or _ShR(num And &HFF000000000000&&, 40) '7
temp = temp Or _ShR(num And &HFF00000000000000&&, 56) '8
SwapEnd = temp
End Function