Click to See Complete Forum and Search --> : long to byte
Martin
November 10th, 1999, 02:45 AM
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
chip@iafrica.com
Lothar Haensler
November 10th, 1999, 03:14 AM
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.
Martin
November 10th, 1999, 03:52 AM
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
Lothar Haensler
November 10th, 1999, 06:21 AM
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
November 10th, 1999, 06:44 AM
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.
codeguru.com
Copyright Internet.com Inc., All Rights Reserved.