Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

someone please explain me the logic in this vb code

Status
Not open for further replies.

techyfubky

Member level 1
Joined
Jul 7, 2007
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
India
Activity points
1,520
'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...
 

AMK1971

Member level 3
Joined
Nov 13, 2007
Messages
67
Helped
11
Reputation
22
Reaction score
4
Trophy points
1,288
Location
33.688°N73.035°E
Activity points
1,596
It is equivalent to

SendBuff(6 ) = (amount / 16777216) And &HFF
SendBuff(7 ) = (amount / 65536) And &HFF
SendBuff(8 ) = (amount / 256) And &HFF
SendBuff(9 ) = amount And &HFF
 

techyfubky

Member level 1
Joined
Jul 7, 2007
Messages
34
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,286
Location
India
Activity points
1,520
@AMK Thanks for your explanation.

Actual operation in which this code is a part of is in writing a numerical value into a block of size 16 byte.

I want to know how this manipulation affects in storing what value in which place..

Can someone show light on this issue please...!
 

AMK1971

Member level 3
Joined
Nov 13, 2007
Messages
67
Helped
11
Reputation
22
Reaction score
4
Trophy points
1,288
Location
33.688°N73.035°E
Activity points
1,596
This code is not affecting the order of bytes, but shifts it 6 places between Receive and send buffer.

i.e. RecvBuff(3) has the Least significant Byte which actually goes to SendBuff(9).
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Top