techyfubky
Member level 1
'Shift bit to the right
dim tempval, amount as long
Dim SendBuff(0 To 255) As Byte
tempval = amount
For index = 1 To 24
tempval = tempval / 2
Next index
SendBuff(6) = tempval And &HFF
tempval = amount
For index = 1 To 16
tempval = tempval / 2
Next index
SendBuff(7) = tempval And &HFF
tempval = amount
For index = 1 To 8
tempval = tempval / 2
Next index
SendBuff(8) = tempval And &HFF
SendBuff(9) = amount And &HFF
The above code splits the Long value "amount " into bytes some lsb in sendbuff(9)..
Please explain me how this happens.....!
Also the following code
' RecvBuff(3)=234, (RecvBuff(2)=1 the values in the bytes
amount = RecvBuff(3)
amount = amount + (RecvBuff(2) * 256)
amount = amount + (RecvBuff(1) * 65536) '256 * 256
amount = amount + (RecvBuff(0) * 16777216) '256 * 256 * 256
tbValue.Text = CStr(amount)
' obtained result is 490' I really dont get the idea behind this logic...
dim tempval, amount as long
Dim SendBuff(0 To 255) As Byte
tempval = amount
For index = 1 To 24
tempval = tempval / 2
Next index
SendBuff(6) = tempval And &HFF
tempval = amount
For index = 1 To 16
tempval = tempval / 2
Next index
SendBuff(7) = tempval And &HFF
tempval = amount
For index = 1 To 8
tempval = tempval / 2
Next index
SendBuff(8) = tempval And &HFF
SendBuff(9) = amount And &HFF
The above code splits the Long value "amount " into bytes some lsb in sendbuff(9)..
Please explain me how this happens.....!
Also the following code
' RecvBuff(3)=234, (RecvBuff(2)=1 the values in the bytes
amount = RecvBuff(3)
amount = amount + (RecvBuff(2) * 256)
amount = amount + (RecvBuff(1) * 65536) '256 * 256
amount = amount + (RecvBuff(0) * 16777216) '256 * 256 * 256
tbValue.Text = CStr(amount)
' obtained result is 490' I really dont get the idea behind this logic...