all groups > vb.net > september 2007 >
vb.net :
String to Hex
On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk> [quoted text, click to view] wrote: > I have the string "15" which I need represented as a hex number - ie &H15 > > Simple I would have thought but I can't find the answer. > > -Jerry
It would be: Dim int As Integer = Integer.Parse("15", Globalization.NumberStyles.HexNumber) If I remember correctly Thanks, Seth Rowe
On Sep 13, 10:21 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk> [quoted text, click to view] wrote: > "rowe_newsgroups" <rowe_em...@yahoo.com> wrote in message > > news:1189692756.040735.155660@r34g2000hsd.googlegroups.com... > > > On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk> > > wrote: > >> I have the string "15" which I need represented as a hex number - ie &H15 > > >> Simple I would have thought but I can't find the answer. > > >> -Jerry > > > It would be: > > > Dim int As Integer = Integer.Parse("15", > > Globalization.NumberStyles.HexNumber) > > > If I remember correctly > > > Thanks, > > > Seth Rowe > > That converts the number to 21. I need to keep 15. I have tried starting > with a string of "&H15" and playing around with that but still can't seem to > do it. > > -Jerry
Sorry, I apparently misunderstood what you are trying to do. As a matter of fact - I still have no idea what you are trying to do. Could you try explaining in more detail what exactly you are trying to do and why? Thanks, Seth Rowe
On Sep 13, 10:36 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk> [quoted text, click to view] wrote: > "rowe_newsgroups" <rowe_em...@yahoo.com> wrote in message > > news:1189693849.797009.237890@r29g2000hsg.googlegroups.com... > > > > > On Sep 13, 10:21 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk> > > wrote: > >> "rowe_newsgroups" <rowe_em...@yahoo.com> wrote in message > > >>news:1189692756.040735.155660@r34g2000hsd.googlegroups.com... > > >> > On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk> > >> > wrote: > >> >> I have the string "15" which I need represented as a hex number - ie > >> >> &H15 > > >> >> Simple I would have thought but I can't find the answer. > > >> >> -Jerry > > >> > It would be: > > >> > Dim int As Integer = Integer.Parse("15", > >> > Globalization.NumberStyles.HexNumber) > > >> > If I remember correctly > > >> > Thanks, > > >> > Seth Rowe > > >> That converts the number to 21. I need to keep 15. I have tried starting > >> with a string of "&H15" and playing around with that but still can't seem > >> to > >> do it. > > >> -Jerry > > > Sorry, I apparently misunderstood what you are trying to do. > > > As a matter of fact - I still have no idea what you are trying to do. > > Could you try explaining in more detail what exactly you are trying to > > do and why? > > > Thanks, > > > Seth Rowe > > Thanks Seth > > I have "15" as a string. I need to do some XOR and ANDing of bits. I can't > directly do: > > "15" AND 01 > > so I need to make 15 a hex value first (&H15). I feel I need something like > ctype(integer,hexvalue) if such a thing existed. I'm sure I will kick myself > when I find the answer. > > -Jerry
Can't you just use the byte datatype instead of string? Thanks, Seth Rowe
[quoted text, click to view] > That converts the number to 21. I need to keep 15. I have tried > starting with a string of "&H15" and playing around with that but > still can't seem to do it.
&H15 *is* 21 in decimal (and integers are stored in decimal) If you're just after the string "&H15" from a string of "15" then just add "&H" on the front.. I guess we're just not clear on what you want. Perhaps it would help if you explain what you would like to do with what you end up with? -- Rory
[quoted text, click to view] > I have "15" as a string. I need to do some XOR and ANDing of bits. I > can't directly do: > > "15" AND 01 > > so I need to make 15 a hex value first (&H15). I feel I need > something like ctype(integer,hexvalue) if such a thing existed. I'm > sure I will kick myself when I find the answer.
Bitwise ANDing of 2 numbers should work regardless of whether they are decimal or hex because internally the mahince only understands nbbinary anyway. Thus ------------------------------------- Dim Result as Integer = CInt("&H" & "15") AND CInt("01") ------------------------------------- This is untested but should result in "Result" containing an integer in this case 1 (Also 1 in HEX) Does this help? -- Rory
I have the string "15" which I need represented as a hex number - ie &H15 Simple I would have thought but I can't find the answer. -Jerry
[quoted text, click to view] "rowe_newsgroups" <rowe_email@yahoo.com> wrote in message news:1189692756.040735.155660@r34g2000hsd.googlegroups.com... > On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk> > wrote: >> I have the string "15" which I need represented as a hex number - ie &H15 >> >> Simple I would have thought but I can't find the answer. >> >> -Jerry > > It would be: > > Dim int As Integer = Integer.Parse("15", > Globalization.NumberStyles.HexNumber) > > If I remember correctly > > Thanks, > > Seth Rowe >
That converts the number to 21. I need to keep 15. I have tried starting with a string of "&H15" and playing around with that but still can't seem to do it. -Jerry
[quoted text, click to view] "rowe_newsgroups" <rowe_email@yahoo.com> wrote in message news:1189693849.797009.237890@r29g2000hsg.googlegroups.com... > On Sep 13, 10:21 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk> > wrote: >> "rowe_newsgroups" <rowe_em...@yahoo.com> wrote in message >> >> news:1189692756.040735.155660@r34g2000hsd.googlegroups.com... >> >> > On Sep 13, 10:04 am, "Jerry Spence1" <jerry.spe...@somewhere.co.uk> >> > wrote: >> >> I have the string "15" which I need represented as a hex number - ie >> >> &H15 >> >> >> Simple I would have thought but I can't find the answer. >> >> >> -Jerry >> >> > It would be: >> >> > Dim int As Integer = Integer.Parse("15", >> > Globalization.NumberStyles.HexNumber) >> >> > If I remember correctly >> >> > Thanks, >> >> > Seth Rowe >> >> That converts the number to 21. I need to keep 15. I have tried starting >> with a string of "&H15" and playing around with that but still can't seem >> to >> do it. >> >> -Jerry > > Sorry, I apparently misunderstood what you are trying to do. > > As a matter of fact - I still have no idea what you are trying to do. > Could you try explaining in more detail what exactly you are trying to > do and why? > > Thanks, > > Seth Rowe >
Thanks Seth I have "15" as a string. I need to do some XOR and ANDing of bits. I can't directly do: "15" AND 01 so I need to make 15 a hex value first (&H15). I feel I need something like ctype(integer,hexvalue) if such a thing existed. I'm sure I will kick myself when I find the answer. -Jerry
[quoted text, click to view] "Rory Becker" <RoryBecker@newsgroup.nospam> wrote in message news:b0ac48a01bd098c9c436d012e480@msnews.microsoft.com... >> I have "15" as a string. I need to do some XOR and ANDing of bits. I >> can't directly do: >> >> "15" AND 01 >> >> so I need to make 15 a hex value first (&H15). I feel I need >> something like ctype(integer,hexvalue) if such a thing existed. I'm >> sure I will kick myself when I find the answer. > > Bitwise ANDing of 2 numbers should work regardless of whether they are > decimal or hex because internally the mahince only understands nbbinary > anyway. > Thus ------------------------------------- > Dim Result as Integer = CInt("&H" & "15") AND CInt("01") > ------------------------------------- > > This is untested but should result in "Result" containing an integer in > this case 1 (Also 1 in HEX) > > Does this help? > > -- > Rory > >
Thanks Rory - yes it does help. I didn't realise that I could so bitwise comparisons on a decimal number. It works OK. Thanks a lot and thanks to Seth for your input as well. -Jerry
[quoted text, click to view] "Armin Zingler" <az.nospam@freenet.de> wrote in message news:%23OGtnkh9HHA.1204@TK2MSFTNGP03.phx.gbl... > "Jerry Spence1" <jerry.spence@somewhere.co.uk> schrieb >> > >> >> Thanks Seth >> >> I have "15" as a string. I need to do some XOR and ANDing of bits. I >> can't directly do: >> >> "15" AND 01 >> >> so I need to make 15 a hex value first (&H15). I feel I need >> something like ctype(integer,hexvalue) if such a thing existed. I'm >> sure I will kick myself when I find the answer. > > Why is "15" there as a string not as a number? If that's not avoidable, > use Convert.ToInt32 to convert it to an integer first, then use numeric > operators. > > dim number as integer > > number = convert.toint32("15", 16) '16 is the base (hexadecimal) > number = number and 1 > > > > > Armin
That's a neat trick. Thanks Armin -Jerry
"Jerry Spence1" <jerry.spence@somewhere.co.uk> schrieb [quoted text, click to view] > > > > Thanks Seth > > I have "15" as a string. I need to do some XOR and ANDing of bits. I > can't directly do: > > "15" AND 01 > > so I need to make 15 a hex value first (&H15). I feel I need > something like ctype(integer,hexvalue) if such a thing existed. I'm > sure I will kick myself when I find the answer.
Why is "15" there as a string not as a number? If that's not avoidable, use Convert.ToInt32 to convert it to an integer first, then use numeric operators. dim number as integer number = convert.toint32("15", 16) '16 is the base (hexadecimal) number = number and 1 Armin
[quoted text, click to view] Jerry Spence1 wrote: > Thanks Rory - yes it does help. I didn't realise that I could so bitwise > comparisons on a decimal number. It works OK.
Actually it's not a decimal number at all, it's just an integer. Decimal and hexadecimal are two ways of representing numbers as text. As long as you handle the integer as an integer, it doesn't have any textual representation at all, it's just some bits in memory. Whenever you display the value of an integer, a string is created that is the textual representation of the integer, as the integer itself can't be displayed as text. -- Göran Andersson _____
Hi Jerry, To convert a string into HEX you need to it char by char ie: convert every char into it's ascii value then convert the ascii to HEX: here is the code: Private Sub txtNormal_TextChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles txtNormal.TextChanged Dim sTemp As String Dim sTemp2 As StringBuilder = New StringBuilder For i As Integer = 0 To Me.txtNormal.Text.Length - 1 sTemp = Me.txtNormal.Text.Substring(i, 1) sTemp2.Append(Hex(Asc(sTemp))) Next Me.txtHEX.Text = sTemp2.ToString() End Sub hope this will help cheers [quoted text, click to view] "Jerry Spence1" <jerry.spence@somewhere.co.uk> wrote in message news:13eigqtocs68p88@corp.supernews.com... >I have the string "15" which I need represented as a hex number - ie &H15 > > Simple I would have thought but I can't find the answer. > > -Jerry > >
Don't see what you're looking for? Try a search.
|
|
|