Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

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

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
157 views
Welcome To Ask or Share your Answers For Others

1 Answer

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"

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...