3 Replies - 545 Views - Last Post: 11 August 2009 - 02:09 PM Rate Topic: -----

#1 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

Can someone explain this code for me please

Posted 11 August 2009 - 12:26 PM

hi all i dont really know anything of php but a mate gave me this code he made for a webapp so i can get the idea on how to make a desktop app in VB.NET so my question is please can someone explain this code so i can try and find a way to it in in vb.net ( this code is to decode data from a udp packet i recieve when querying a game server to list in my server browser (can supply full php code if needed)

function byte4toint($procnumber)
{
  return ord($procnumber{0}) + (ord($procnumber{1}) << 8) + (ord($procnumber{2}) << 16) + (ord($procnumber{3}) << 24);
}

function byte2toint($procnumber)
{
  return ord($procnumber{0}) + (ord($procnumber{1}) << 8);
}



now i thought i had sorted it in vb.net as the byte4toint works fine and gives me the correct infomation but byte2toint dont... byte2toint is to get the Port number the server is running on and its giving me the wrong port number but also giving me the same port number for all servers thats running on different ports, this is what i have done in vb.net (neary the same as php)

 Function byte4toint(ByVal proc4number)

		Return Asc(proc4number(0)) + (Asc(proc4number(1)) << 8) + (Asc(proc4number(1)) << 16) + (Asc(proc4number(3)) << 24)

	End Function

	Function byte2toint(ByVal PortNumber)

		Return Asc(PortNumber(0)) + (Asc(PortNumber(1)) << 8)

	End Function



thanks for your time to read this

Kev

Is This A Good Question/Topic? 0
  • +

Replies To: Can someone explain this code for me please

#2 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2913
  • View blog
  • Posts: 10,088
  • Joined: 08-August 08

Re: Can someone explain this code for me please

Posted 11 August 2009 - 12:40 PM

View PostTADS, on 11 Aug, 2009 - 03:26 PM, said:

function byte4toint($procnumber)
{
  return ord($procnumber{0}) + (ord($procnumber{1}) << 8) + (ord($procnumber{2}) << 16) + (ord($procnumber{3}) << 24);
}

function byte2toint($procnumber)
{
  return ord($procnumber{0}) + (ord($procnumber{1}) << 8);
}


byte4toint returns the ascii value of the first character + the ascii value of the second character shifted 8 bits to the left + the ascii value of the third character shifted 16 bits to the left + the ascii value of the fourth character shifted 24 bits to the left. This essentially reverses the order of the first four characters and returns them as an integer.

byte2point does the same but with just the first two characters.

This post has been edited by CTphpnwb: 11 August 2009 - 02:13 PM

Was This Post Helpful? 0
  • +
  • -

#3 TADS  Icon User is offline

  • D.I.C Head
  • member icon

Reputation: 10
  • View blog
  • Posts: 161
  • Joined: 09-August 08

Re: Can someone explain this code for me please

Posted 11 August 2009 - 01:15 PM

Thanks for the reply

i dont know what to do then from here as the byte4toint works fine but byte2toint dont, just showing same port (wrong one that that) for all servers (so code is wrong in vb.net somewhere)

thanks for replying tho and giving me the info :)

Kev
Was This Post Helpful? 0
  • +
  • -

#4 CTphpnwb  Icon User is offline

  • D.I.C Lover
  • member icon

Reputation: 2913
  • View blog
  • Posts: 10,088
  • Joined: 08-August 08

Re: Can someone explain this code for me please

Posted 11 August 2009 - 02:09 PM

You should post the VB problem in the VB6 forum.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1