-
Need to Convert a Hex string to a Hex number
Okay, here is the story...
strTemp = "95CD4F8A"
Dim lTest2 As Int64 = HexToLong(strTemp) ' lTest2 = 2513260426
I have a hex string, strTemp that needs to be assigned as a _hex value_ to
i32Test. I cannot assign it directly because it overflows the Int32
variable. But if I assign it to the Int32 variable as a hex value the
assignment goes okay and i32Test is then equal to -1781706870...
Dim i32Test As Int32 = &H95CD4F8A
The variable strTemp changes with each call to Guid.NewGuid() so I cannot
hard code the hex value in the assignment. How do I convert the string
"95CD4F8A" to an Int32 variable?
Maybe I've been working on this too much today and am overlooking the
obvious. And I need a break from this project which I plan on taking as
soon as I send this. I have other projects to work on and newsgroups to
catch up on!
Dan
-
Re: Need to Convert a Hex string to a Hex number
Thanks!, that was the one I was looking for.
In VB6 when I wanted to convert a hex number I had written a routine that
walked the string doing something crazy like (16 ^ i) * chrDigit to convert
it to a number. Now ToInt32 takes care of it for me. Nice.
strTemp = "DAC85243"
Dim i32Test As Int32 = System.Convert.ToInt32(strTemp,16)
i32Test = -624405949
Dan
"Michael (michka) Kaplan" <former_mvp@spamfree.trigeminal.nospam.com> wrote
in message news:3b8487ee$1@news.devx.com...
> System.Convert.ToInt32 has a signature that takes a string and a "base"
as
> params. Just use this conversion and a base of 16.
>
> --
> MichKa
>
> the only book on internationalization in VB at
> http://www.i18nWithVB.com/
>
> "Dan Fergus" <dan@vbforest.com> wrote in message
> news:3b8461a9$1@news.devx.com...
> > Okay, here is the story...
> >
> > strTemp = "95CD4F8A"
> > Dim lTest2 As Int64 = HexToLong(strTemp) ' lTest2 = 2513260426
> >
> > I have a hex string, strTemp that needs to be assigned as a _hex value_
to
> > i32Test. I cannot assign it directly because it overflows the Int32
> > variable. But if I assign it to the Int32 variable as a hex value the
> > assignment goes okay and i32Test is then equal to -1781706870...
> >
> > Dim i32Test As Int32 = &H95CD4F8A
> >
> > The variable strTemp changes with each call to Guid.NewGuid() so I
cannot
> > hard code the hex value in the assignment. How do I convert the string
> > "95CD4F8A" to an Int32 variable?
> >
> > Maybe I've been working on this too much today and am overlooking the
> > obvious. And I need a break from this project which I plan on taking as
> > soon as I send this. I have other projects to work on and newsgroups to
> > catch up on!
> >
> > Dan
> >
> >
> >
>
>
-
Re: Need to Convert a Hex string to a Hex number
> In VB6 when I wanted to convert a hex number I had
> written a routine that walked the string doing something
> crazy like (16 ^ i) * chrDigit to convert it to a number.
Dan: Why not simply:
Value = Val("&H" & strHex)
;-)
---
Phil Weber
-
Re: Need to Convert a Hex string to a Hex number
Well ....
When I tried --->> Value = Val(strHex)
and it just coverts the first chahracter. Never tried putting the "&" in
front of it first. Sometimes I just make things too hard :-)
Dan
"Phil Weber" <pweber@devx.com> wrote in message
news:3b85299f$1@news.devx.com...
> > In VB6 when I wanted to convert a hex number I had
> > written a routine that walked the string doing something
> > crazy like (16 ^ i) * chrDigit to convert it to a number.
>
> Dan: Why not simply:
>
> Value = Val("&H" & strHex)
>
> ;-)
> ---
> Phil Weber
>
>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
Forum Rules
|
Top DevX Stories
Easy Web Services with SQL Server 2005 HTTP Endpoints
JavaOne 2005: Java Platform Roadmap Focuses on Ease of Development, Sun Focuses on the "Free" in F.O.S.S.
Wed Yourself to UML with the Power of Associations
Microsoft to Add AJAX Capabilities to ASP.NET
IBM's Cloudscape Versus MySQL
|
Bookmarks