473,480 Members | 2,230 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

string conversion - hex to int

Hi,

any ideas: how can i convert "0x12" to int in C#?
Kimmo Laine
Nov 16 '05 #1
4 44501
Convert.ToInt32("0x12", 16);

Yves

"Kimmo Laine" <reply.to@newsgroup> schreef in bericht
news:e9**************@TK2MSFTNGP12.phx.gbl...
Hi,

any ideas: how can i convert "0x12" to int in C#?
Kimmo Laine

Nov 16 '05 #2
Convert.ToInt32("0x12", 16);

Yves

"Kimmo Laine" <reply.to@newsgroup> schreef in bericht
news:e9**************@TK2MSFTNGP12.phx.gbl...
Hi,

any ideas: how can i convert "0x12" to int in C#?
Kimmo Laine

Nov 16 '05 #3
Hi

Use the following:

string hex = "B1242AF2";
int n = Int32.Parse( hex, System.Globalization.NumberStyles.HexNumber );

Alternatively, the following will also work.

string hex = "B1242AF2";
int myHex = Convert.ToInt32( hex, 16 );

See here for sample application

http://www.publicjoe.f9.co.uk/csharp/snip/snip035.html

Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html

"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
Hi,

any ideas: how can i convert "0x12" to int in C#?
Kimmo Laine

Nov 16 '05 #4
Hi

Use the following:

string hex = "B1242AF2";
int n = Int32.Parse( hex, System.Globalization.NumberStyles.HexNumber );

Alternatively, the following will also work.

string hex = "B1242AF2";
int myHex = Convert.ToInt32( hex, 16 );

See here for sample application

http://www.publicjoe.f9.co.uk/csharp/snip/snip035.html

Hope this helps

Publicjoe
C# Tutorial at http://www.publicjoe.f9.co.uk/csharp/tut.html
C# Snippets at http://www.publicjoe.f9.co.uk/csharp/snip/snippets.html

"Kimmo Laine" <reply.to@newsgroup> wrote in message
news:e9**************@TK2MSFTNGP12.phx.gbl...
Hi,

any ideas: how can i convert "0x12" to int in C#?
Kimmo Laine

Nov 16 '05 #5

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
66868
by: Keiron Waites | last post by:
I get the following error: Notice: Array to string conversion in C:\Documents and Settings\ShepMode\Desktop\Websites\ShareMonkey.net\Web\join.php on line 11 in this code: $input =...
8
2174
by: John van Terheijden | last post by:
Hi. I'm trying to make a conversion algorithm that colors even and odd words in a HTML string with <div> tags. // input text with all sorts of HTML tags and whitespace $str = "<h1>Title...
3
3717
by: praba kar | last post by:
Dear All, I have doubt regarding date string to time conversion function. In Python I cannot find flexible date string conversion function like php strtotime. I try to use following type...
8
424
by: alex | last post by:
i have a string "dasfk" stored in a variable of type string and i want to convert it to const _bstr_t, anybody know? Posted Via Usenet.com Premium Usenet Newsgroup Services...
3
3302
by: RC | last post by:
Just wondering if there are good reasons (performance, ?) to use one of these string conversion alternatives over the other: 1. Convert.ToString() 2. someObject.ToString() Example:...
8
4324
by: Duncan Winn | last post by:
I am new to VC++7. I am using a method GetPrivateProfileString that requires an LPTSTR. I have defined this as a: char * data_name; I am then trying to convert this to an LPOLESTR and I...
18
34062
by: Ger | last post by:
I have not been able to find a simple, straight forward Unicode to ASCII string conversion function in VB.Net. Is that because such a function does not exists or do I overlook it? I found...
4
5517
by: Russell Warren | last post by:
I've got a case where I want to convert binary blocks of data (various ctypes objects) to base64 strings. The conversion calls in the base64 module expect strings as input, so right now I'm...
26
6243
by: drako | last post by:
Hi, I'm a bit stumped as I am getting a "Notice: Array to String Conversion" error when trying to do something that on the surface should be a very simple task - create an array, and write a set...
2
4950
by: Saeed Amrollahi | last post by:
Dear All Hi I usually use the following function for built-in types to std::string conversion: // convert a type (typically built-in type) to std::string template<class T> inline std::string...
0
7049
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
6912
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
7052
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
7092
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
4790
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...
0
3000
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The...
0
2989
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
565
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
188
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.