Anyone plse help
How do I convert a long data type to 2 bytes
cbyte only converts to one byte
This is to transmit a long crc computation result
by com
Thanks,
Martin
[email protected]
Printable View
Anyone plse help
How do I convert a long data type to 2 bytes
cbyte only converts to one byte
This is to transmit a long crc computation result
by com
Thanks,
Martin
[email protected]
no need to convert
Dim lon as Long
Dim intv as Integer
lon = 123
intv = lon
unless you get an error, because the long value is too big.
That is just my problem that the long is too large
for one byte I need to get it into a high and low byte
try these functions...
private Function HiWord(dw as Long) as Integer
If dw And &H80000000 then
HiWord = (dw \ 65535) - 1
else
HiWord = dw \ 65535
End If
End Function
private Function LoByte(w as Integer) as Byte
LoByte = w And &HFF
End Function
private Function LoWord(dw as Long) as Integer
If dw And &H8000& then
LoWord = &H8000 Or (dw And &H7FFF&)
else
LoWord = dw And &HFFFF&
End If
End Function
private Function HiByte(byval w as Integer) as Byte
If w And &H8000 then
HiByte = &H80 Or ((w And &H7FFF) \ &HFF)
else
HiByte = w \ 256
End If
End Function
Dim v(3) as Byte, x as Long
...
...
...
for i = 0 to 3
v(i) = x Mod 256
x = Int(x / 256)
next
v contains the four bytes, from
the lowest to the highest one.