Code |
SwapEndian01 |
Public Function SwapEndian01(ByVal dw As Long) As Long
' by Anonymous, not dated
CopyMemory ByVal VarPtr(SwapEndian01) + 3, dw, 1
CopyMemory ByVal VarPtr(SwapEndian01) + 2, ByVal VarPtr(dw) + 1, 1
CopyMemory ByVal VarPtr(SwapEndian01) + 1, ByVal VarPtr(dw) + 2, 1
CopyMemory SwapEndian01, ByVal VarPtr(dw) + 3, 1
End Function
|
SwapEndian02 |
Private Type T1Long
lDWord As Long
End Type
Private Type T4Byte
bByte1 As Byte 'lo
bByte2 As Byte
bByte3 As Byte
bByte4 As Byte 'hi
End Type
Public Function SwapEndian02(ByVal dw As Long) As Long
' by Matthew Curland, mattcur@microsoft.com, 20010601
Dim u4Byte1 As T4Byte
Dim u4Byte2 As T4Byte
Dim u1Long As T1Long
u1Long.lDWord = dw
LSet u4Byte1 = u1Long
With u4Byte1
u4Byte2.bByte1 = .bByte4
u4Byte2.bByte2 = .bByte3
u4Byte2.bByte3 = .bByte2
u4Byte2.bByte4 = .bByte1
End With
LSet u1Long = u4Byte2
SwapEndian02 = u1Long.lDWord
End Function
|
SwapEndian03 |
Public Function SwapEndian03(ByVal dw As Long) As Long
' by Donald, donald@xbeat.net, 20040808
Dim b1 As Long
Dim b2 As Long
Dim b3 As Long
Dim b4 As Long
Dim lHighBit As Long
' handle sign bit
lHighBit = dw And &H80000000
If lHighBit Then
dw = dw And Not &H80000000
End If
b1 = dw And &HFF
b2 = (dw And &HFF00&) \ &H100&
b3 = (dw And &HFF0000) \ &H10000
b4 = (dw And &HFF000000) \ &H1000000
If lHighBit Then
b4 = b4 Or &H80
End If
If b1 And &H80& Then
SwapEndian03 = ((b1 And &H7F&) * &H1000000 Or &H80000000) + _
b2 * &H10000 + b3 * &H100& + b4
Else
SwapEndian03 = b1 * &H1000000 + b2 * &H10000 + b3 * &H100& + b4
End If
End Function
|
SwapEndian04 |
Public Function SwapEndian04(ByVal dw As Long) As Long
' by FireBot, fire_bot@hotmail.com, 20040809
Dim lngTmp As Long
Dim dblTmp As Double
dblTmp = CDbl(dw And &HFF&) * &H1000000
If dblTmp > 2147483647 Then lngTmp = dblTmp - 4294967296# Else lngTmp = dblTmp
lngTmp = lngTmp Or ((dw And &HFF00&) * &H100)
lngTmp = lngTmp Or ((dw And &HFF0000) \ &H100)
lngTmp = lngTmp Or (((dw And &HFF000000) \ &H1000000) And &HFF)
SwapEndian04 = lngTmp
End Function
|
SwapEndian05 |
Public Function SwapEndian05(ByVal dw As Long) As Long
' by Paul, wpsjr1@syix.com, 20040809
Dim b1 As Long
Dim b2 As Long
Dim b3 As Long
Dim b4 As Long
Dim lHighBit As Long
Dim lLoBit As Long
lHighBit = dw And &H80000000
dw = dw And &H7FFFFFFF
b1 = dw And &H7F
lLoBit = dw And &H80
b2 = (dw And &HFF00&)
b3 = (dw And &HFF0000) \ &H100
b4 = dw \ &H1000000
b4 = b4 Or ((lHighBit \ &H1000000) And &HFF)
SwapEndian05 = (b1 * &H1000000) Or (b2 * &H100) Or b3 Or b4
If lLoBit Then SwapEndian05 = SwapEndian05 Or &H80000000
End Function
|
SwapEndian06 |
Private Declare Function htonl Lib "wsock32.dll" (ByVal hostlong As Long) As Long
Public Function SwapEndian06(ByVal dw As Long) As Long
' by Paul, wpsjr1@syix.com, 20040809
SwapEndian06 = htonl(dw)
End Function
|
SwapEndian07 |
Public Function SwapEndian07(ByVal dw As Long) As Long
' by Donald, donald@xbeat.net, 20040809
Dim b1 As Long
Dim b2 As Long
Dim b3 As Long
Dim b4 As Long
Dim lHighBit As Long
lHighBit = dw And &H80000000
If lHighBit Then
dw = dw And Not &H80000000
End If
b1 = dw And &HFF
b2 = (dw And &HFF00&) \ &H100&
b3 = (dw And &HFF0000) \ &H10000
If lHighBit Then
b4 = dw \ &H1000000 Or &H80
Else
b4 = dw \ &H1000000
End If
If b1 And &H80& Then
SwapEndian07 = ((b1 And &H7F&) * &H1000000 Or &H80000000) Or _
b2 * &H10000 Or b3 * &H100& Or b4
Else
SwapEndian07 = b1 * &H1000000 Or _
b2 * &H10000 Or b3 * &H100& Or b4
End If
End Function
|
SwapEndian08 |
Public Function SwapEndian08(ByVal dw As Long) As Long
' by Mike D Sutton, Mike.Sutton@btclick.com, 20040914
SwapEndian08 = _
(((dw And &HFF000000) \ &H1000000) And &HFF&) Or _
((dw And &HFF0000) \ &H100&) Or _
((dw And &HFF00&) * &H100&) Or _
((dw And &H7F&) * &H1000000)
If (dw And &H80&) Then SwapEndian08 = SwapEndian08 Or &H80000000
End Function
|
Calls |
1 | sRet = SwapEndian(&H12345678) --> [=&H78563412]
|
2 | sRet = SwapEndian(&H80&) --> [=&H80000000]
|
3 | sRet = SwapEndian(&H80000000) --> [=&H80&]
|
4 | sRet = SwapEndian(&H80808080) --> [=&H80808080]
|
Charts |