Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Endian swapping in QB64pe
#6
(03-22-2025, 03:25 PM)SMcNeill Wrote: 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
Thanks @SMcNeil, but I see this as not really acceptable in a language where I have explicitly declared the variable type, and I would have used OPTION _EXPLICIT also to make sure all my variables were correctly type declared to then have to use type suffixes too.

Too many unnecessary temporary variables also mixing unsigned and signed, although my code above uses 2, I only did that for clarity/sanity.  My original code was a function that worked on the reference and passed that back. Is this a quirk/niggle of QB64pe that will stay?
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

Possibly Related Threads…
Thread Author Replies Views Last Post
  Swapping array elements PhilOfPerth 24 3,917 11-19-2022, 12:16 AM
Last Post: Pete

Forum Jump:


Users browsing this thread: 1 Guest(s)