|
-
November 10th, 1999, 03:45 AM
#1
long to byte
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]
-
November 10th, 1999, 04:14 AM
#2
Re: long to byte
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.
-
November 10th, 1999, 04:52 AM
#3
Re: long to byte
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
-
November 10th, 1999, 07:21 AM
#4
Re: long to 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
-
November 10th, 1999, 07:44 AM
#5
Re: long to byte
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.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|