Local p@ Ptr = "blah".ToWString( )ReverseBytes( p, 8, False )Print Bin( Int Ptr(p)[0] )Print String.FromShorts( Short Ptr(p), 8 )ReverseBytes( p, 8, False )Print Bin( Int Ptr(p)[0] )ReverseBytes( p, 8, True )Print Bin( Int Ptr(p)[0] )Print String.FromShorts( Short Ptr(p), 8 )ReverseBytes( p, 8, True )Print Bin( Int Ptr(p)[0] )Print String.FromShorts( Short Ptr(p), 8 )ReverseBytes( p, 8, True )Print Bin( Int Ptr(p)[0] )ReverseBytes( p, 8, False )Print Bin( Int Ptr(p)[0] )Print String.FromShorts( Short Ptr(p), 8 )ReverseBytes( p, 8, False )Print Bin( Int Ptr(p)[0] )ReverseBytes( p, 8, True )Print Bin( Int Ptr(p)[0] )Print String.FromShorts( Short Ptr(p), 8 )Local t% = Millisecs( )For Local i% = 0 To 99999 ReverseBytes(p,8,True)Nextt = Millisecs( ) - tPrint "Time taken with rbits as True: "+t+"ms"Print "Time taken per call with rbits as True average: "+(t*0.00001)+"ms"t = Millisecs( )For Local i% = 0 To 199999 ReverseBytes(p,8,False)Nextt = Millisecs( ) - tPrint "Time taken with rbits as False: "+t+"ms"Print "Time taken per call with rbits as False average: "+(t*0.00001)+"ms"MemFree( p ) ' Ok, we're done with the memoryPrint Bin(%10000000)[24..]Print Bin(ReverseBits( %10000000 ))[24..]Print Bin(%11000000)[24..]Print Bin(ReverseBits( %11000000 ))[24..]Print Bin(%10100000)[24..]Print Bin(ReverseBits( %10100000 ))[24..]Print Bin(%00000011)[24..]Print Bin(ReverseBits( %00000011 ))[24..]Input( )
Function ReverseBits@( p@ ) Local p2:Int=((p & %11110000) Shr 4) | ((p & %1111) Shl 4) p=((p2 & %11001100) Shr 2) | ((p2 & %110011) Shl 2) Return ((p & %10101010) Shr 1) | ((p & %1010101) Shl 1)End Function
Function ReverseBitsA@( p@ ) ?Debug Return (p & %1) Shl 7.. | ((p&%10000000) Shr 7).. | (p & %10) Shl 5.. | ((p&%1000000) Shr 5).. | (p & %100) Shl 3.. | ((p&%100000) Shr 3).. | (p & %1000) Shl 1.. | ((p&%10000) Shr 1) ? Local p2:Int = ((p & %11110000) Shr 4) | ((p & %1111) Shl 4) p =((p & %11001100) Shr 2) | ((p & %110011) Shl 2) Return ((p & %10101010) Shr 1) | ((p & %1010101) Shl 1)End Function