PC Review


Reply
Thread Tools Rate Thread

convert string to integer (hex)

 
 
Panhuber Astrid
Guest
Posts: n/a
 
      1st Mar 2004
hi!

can anyone please give me a hint, how to convert a hex-string to an integer?

I know how to convert a decimal string (such as "51", "27", ...):
n = System.Convert.ToInt32(str);

But how to convert a hex string (such as "4C" or "0x4C")? If I use the same
function, it throws me an exception.



Thanks in advance,

astrid


 
Reply With Quote
 
 
 
 
Peter Foot [MVP]
Guest
Posts: n/a
 
      1st Mar 2004
The following should work:-

n = Int32.Parse("4C", NumberFormat.HexNumber);


Peter

--
Peter Foot
Windows Embedded MVP
OpenNETCF.org Senior Advisor
www.inthehand.com | www.opennetcf.org

"Panhuber Astrid" <(E-Mail Removed)> wrote in message
news:uwF%23ib6$(E-Mail Removed)...
> hi!
>
> can anyone please give me a hint, how to convert a hex-string to an
> integer?
>
> I know how to convert a decimal string (such as "51", "27", ...):
> n = System.Convert.ToInt32(str);
>
> But how to convert a hex string (such as "4C" or "0x4C")? If I use the
> same
> function, it throws me an exception.
>
>
>
> Thanks in advance,
>
> astrid
>
>



 
Reply With Quote
 
Jacco
Guest
Posts: n/a
 
      1st Mar 2004
...or the ever so gentle:

n = val("&h" & "4C")

even works in the good old VBDOS

Jacco.


"Peter Foot [MVP]" <(E-Mail Removed)> wrote in message
news:ebHk2j6$(E-Mail Removed)...
> The following should work:-
>
> n = Int32.Parse("4C", NumberFormat.HexNumber);
>
>
> Peter
>
> --
> Peter Foot
> Windows Embedded MVP
> OpenNETCF.org Senior Advisor
> www.inthehand.com | www.opennetcf.org
>
> "Panhuber Astrid" <(E-Mail Removed)> wrote in message
> news:uwF%23ib6$(E-Mail Removed)...
> > hi!
> >
> > can anyone please give me a hint, how to convert a hex-string to an
> > integer?
> >
> > I know how to convert a decimal string (such as "51", "27", ...):
> > n = System.Convert.ToInt32(str);
> >
> > But how to convert a hex string (such as "4C" or "0x4C")? If I use the
> > same
> > function, it throws me an exception.
> >
> >
> >
> > Thanks in advance,
> >
> > astrid
> >
> >

>
>



 
Reply With Quote
 
Panhuber Astrid
Guest
Posts: n/a
 
      2nd Mar 2004
hi!

thank you - this one works for me:
n = Int32.Parse(str, System.Globalization.NumberStyles.HexNumber);

thanks,
astrid

"Peter Foot [MVP]" <(E-Mail Removed)> schrieb im Newsbeitrag
news:ebHk2j6$(E-Mail Removed)...
> The following should work:-
>
> n = Int32.Parse("4C", NumberFormat.HexNumber);
>
>
> Peter
>
> --
> Peter Foot
> Windows Embedded MVP
> OpenNETCF.org Senior Advisor
> www.inthehand.com | www.opennetcf.org
>
> "Panhuber Astrid" <(E-Mail Removed)> wrote in message
> news:uwF%23ib6$(E-Mail Removed)...
> > hi!
> >
> > can anyone please give me a hint, how to convert a hex-string to an
> > integer?
> >
> > I know how to convert a decimal string (such as "51", "27", ...):
> > n = System.Convert.ToInt32(str);
> >
> > But how to convert a hex string (such as "4C" or "0x4C")? If I use the
> > same
> > function, it throws me an exception.
> >
> >
> >
> > Thanks in advance,
> >
> > astrid
> >
> >

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
how to convert string into integer in c# Bob Microsoft C# .NET 6 9th Jun 2008 01:21 AM
How to convert from string to integer? Allen Maki Microsoft Dot NET 2 2nd May 2007 01:05 PM
convert HEX string into integer :) Microsoft C# .NET 3 26th May 2006 08:37 PM
How to convert hex string to integer Tanja Krammer Microsoft C# .NET 3 8th Apr 2006 08:46 PM
Convert integer to string =?Utf-8?B?S2Vu?= Microsoft Access Form Coding 1 15th Mar 2004 01:18 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 11:16 AM.