дано: нечто типа long.
нужно получить в виде отдельных чисел первые и последние 2 байта.
Не могу сообразить, как это проще всего сделать

Option Explicit
'Простейшие функции для вычленения частей машинных сущностей :)
'(c) GSerg, 2004
'P.S. Через CopyMemory медленнее, через GetMem тоже :)
Public Function DWORD(ByVal Low As Integer, ByVal High As Integer) As Long
If High And &H8000 Then
DWORD = (High And &H7FFF) * &H10000 Or &H80000000 Or Low
Else
DWORD = High * &H10000 Or Low
End If
End Function
Public Function WORD(ByVal Low As Byte, ByVal High As Byte) As Integer
If High And &H80 Then
WORD = (High And &H7F) * &H100 Or &H8000 Or Low
Else
WORD = High * &H100 Or Low
End If
End Function
Public Function HIWORD(ByVal DblWord As Long) As Integer
HIWORD = DblWord / &H10000
End Function
Public Function LOWORD(ByVal DblWord As Long) As Integer
LOWORD = DblWord And &HFFFF&
End Function
Public Function HIBYTE(ByVal Wrd As Integer) As Byte
If Wrd And &H8000 Then
HIBYTE = (Wrd And &H7F00) / &H100 Or &H80
Else
HIBYTE = Wrd / &H100
End If
End Function
Public Function LOBYTE(ByVal Wrd As Integer) As Byte
LOBYTE = Wrd And &HFF
End Function
Public Type tag_4
Four As Long
End Type
Public Type tag_2_2
Lo As Integer
Hi As Integer
End Type
Public Function SplitLong(ByVal L As Long) As tag_2_2
Dim Z As tag_4
Z.Four = L
LSet SplitLong = Z
End Function
Private Sub Command1_Click()
Dim Z As Long, X As tag_2_2
Z = &H64583545
X = SplitLong(Z)
MsgBox "Low = " & Hex(X.Lo) & vbNewLine & "High = " & Hex(X.Hi) & _
vbNewLine & "Number = " & Hex(Z)
End Sub
GSerg писал(а):... Просто сей оператор отменили в .NET ...
Dim Z As tag_4
Z.Four = L
LSet SplitLong = Z
End Function
'Простейшие функции для вычленения частей машинных сущностей![]()
Сейчас этот форум просматривают: Google-бот, Yandex-бот и гости: 15