tags:

views:

44

answers:

2

I am a java devloper and I wish to convert following code to java can any VB devloper tell me what following does?

    temp8Bit = 0
    temp8Bit = Convert.ToByte(tempRMACode.ToCharArray().GetValue(0))
             + Convert.ToByte((tempRMACode.ToCharArray()).GetValue(7))
    rmaValidationCode += String.Format("{0:X2}", temp8Bit)

tempRMACode is a string

+1  A: 

What it's going to do is take the 0th & 7th character from the tempRMACode string, convert those values to Bytes and then add them. Convert is applied to the ASCII value of the character. So Convert.ToByte("A") == 65 the ASCII value of A.

String.Format("{0:X2}", temp8bit) is going to take the numeric value of temp8bit and give you the HEX value. So if you had the number 121 in temp8bit, you'd get 79 in rmaValidationCode.


Given the following:

Dim temp8bit As Byte
Dim tempRMACode As String = "A234567890"

Dim rmaValidationCode As String = String.Empty

temp8Bit = 0
temp8bit = Convert.ToByte(tempRMACode.ToCharArray().GetValue(0)) _
     + Convert.ToByte((tempRMACode.ToCharArray()).GetValue(7))

Dim a As String = tempRMACode.ToCharArray().GetValue(0)
Dim b As String = tempRMACode.ToCharArray().GetValue(7)

Dim c As Byte = Convert.ToByte(tempRMACode.ToCharArray().GetValue(0))
Dim d As Byte = Convert.ToByte(tempRMACode.ToCharArray().GetValue(7))

rmaValidationCode += String.Format("{0:X2}", temp8bit)

the output is:

temp8bit = 121 or 0x79
a = "A"
b = "8"
c = 65
d = 56
rmaValidationCode = "79"
Gavin Miller
A: 

It is adding the byte values of the 1st and the 8th characters of tempRMACode, then appending it to rmaValidationCode in the format of "0:X2" which is a 2-character hexadecimal representation of the string (temp8Bit).

Greg