By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
444,219 Members | 2,361 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 444,219 IT Pros & Developers. It's quick & easy.

Concatenation Revisited...

P: n/a
I took a look at the stringbuilder solutions discussed earlier today... and I have a question that is also tied to a result that is currently having me scratch my head. It looks like this:

Dim hexString1 as String
Dim hexString2 as String
Dim hexResult as String

hexString1 = Hex$(decValue1)
hexString2 = Hex$(decValue2)
hexResult = hexString1 & hexString2

main.output.additem(hexResult)

A couple things to note: hexString1 and hexString2 will always be used to represent one byte of data each. So the range of hexResult would be 0000h to FFFFh.

The code above seems to work in all instances, except in instances where the upper nibble of hexString2 is equal to Zero (ie: XX0Xh). When the value shows up as XX0Xh, the result appears as XX00h.

Is this normal? Any suggestions?
Nov 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
Jvangel,
The following gives what I believe you are asking for:

Dim decValue1 As Byte = 10
Dim decValue2 As Byte = 20
Dim hexResult As String = decValue1.ToString("X2") &
decValue2.ToString("X2")

The "problem" with Hex$ is it will only return a single hex digit for 0 to
15, where as ToString("X2") says you want Hex with 2 digits no matter what.

Hope this helps
Jay
"jvangel" <jv*****@discussions.microsoft.com> wrote in message
news:BB**********************************@microsof t.com...
I took a look at the stringbuilder solutions discussed earlier today... and I have a question that is also tied to a result that is currently having
me scratch my head. It looks like this:
Dim hexString1 as String
Dim hexString2 as String
Dim hexResult as String

hexString1 = Hex$(decValue1)
hexString2 = Hex$(decValue2)
hexResult = hexString1 & hexString2

main.output.additem(hexResult)

A couple things to note: hexString1 and hexString2 will always be used to represent one byte of data each. So the range of hexResult would be 0000h
to FFFFh.
The code above seems to work in all instances, except in instances where the upper nibble of hexString2 is equal to Zero (ie: XX0Xh). When the value
shows up as XX0Xh, the result appears as XX00h.
Is this normal? Any suggestions?

Nov 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.