473,406 Members | 2,843 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,406 software developers and data experts.

string conversion - hex to int

Hi,

any ideas: how can i convert "0x12" to int in C#?
Kimmo Laine
Nov 16 '05 #1
4 44499
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
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
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
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
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
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
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
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
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
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
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
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
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
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
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...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
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...

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.