Code:
UNION BYTE_LONG Bytes(4) AS BYTE l AS LONG END UNION DIM var AS BYTE_LONG var.Bytes(1) = 1998
bytes before assignment to the BYTE variable. So, var.Bytes(2-4) should
not be affected.
------------------
Bernard Ertl
UNION BYTE_LONG Bytes(4) AS BYTE l AS LONG END UNION DIM var AS BYTE_LONG var.Bytes(1) = 1998
#Compile Exe #Dim All #Register None Function PbMain Dim L1 As Long, B1 As Byte, B2 As Byte, B3 As Byte, B4 As Byte L1 = &H01020304 ! MOV AX, L1 ! MOV B4, AL ! MOV B3, AH ! MOV AX, L1[2] ! MOV B2, AL ! MOV B1, AH MsgBox Hex$(B1, 2) + " " + Hex$(B2, 2) + " " + Hex$(B3, 2) + " " + Hex$(B4, 2) End Function
MSB: HIBYT( HIWRD( ... ) ) LOBYT( HIWRD( ... ) ) HIBYT( LOWRD( ... ) ) LSB: LOBYT( LOWRD( ... ) )
UNION BYTE_LONG Bytes(4) AS BYTE l AS LONG END UNION FUNCTION PBMAIN AS LONG LOCAL pByte AS BYTE PTR LOCAL l AS LONG LOCAL u AS BYTE_LONG l = -12983434 u.l = l 'one way pByte = VARPTR(l) PRINT @pByte[0] PRINT @pByte[1] PRINT @pByte[2] PRINT @pByte[3] PRINT "-----" 'another PRINT u.Bytes(0) PRINT u.Bytes(1) PRINT u.Bytes(2) PRINT u.Bytes(3) WAITKEY$ END FUNCTION
Type FourBytes One as Byte Two as Byte Three as Byte Four as Byte End type Union LongBytes Bytes as FourBytes lLong as long end union
Long = WWWWWWWW XXXXXXXX YYYYYYYY ZZZZZZZZ Byte 1 = ZZZZZZZZ Byte 2 = YYYYYYYY Byte 3 = XXXXXXXX Byte 4 = WWWWWWWW
Sub Break_Long_To_Bytes(L1 As Long, B1 As Byte, B2 As Byte, B3 As Byte, B4 As Byte) Dim LNG_1 As Long '// Holding variable for B1 Dim LNG_2 As Long '// Holding variable for B2 Dim LNG_3 As Long '// Holding variable for B3 Dim LNG_4 As Long '// Holding variable for B4 Dim TMPlng As Long '// Temporary Long variable used for shifting TMPlng = L1 LNG_1 = TMPlng Mod 256 TMPlng = TMPlng \ 256 '// Shift 1 Byte LNG_2 = TMPlng Mod 256 TMPlng = TMPlng \ 256 '// Shift 1 Byte again LNG_3 = TMPlng Mod 256 TMPlng = TMPlng \ 256 '// Shift 1 Byte again LNG_4 = TMPlng Mod 256 B1 = LNG_1 '// Set the Most Right Byte -- ZZZZZZZZ B2 = LNG_2 '// Set the Second Right Byte -- YYYYYYYY B3 = LNG_3 '// Set the Second Left Byte -- XXXXXXXX B4 = LNG_4 '// Set the Most Left Byte -- WWWWWWWW End Sub
We process personal data about users of our site, through the use of cookies and other technologies, to deliver our services, and to analyze site activity. For additional details, refer to our Privacy Policy.
By clicking "I AGREE" below, you agree to our Privacy Policy and our personal data processing and cookie practices as described therein. You also acknowledge that this forum may be hosted outside your country and you consent to the collection, storage, and processing of your data in the country where this forum is hosted.
Leave a comment: