473,406 Members | 2,377 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 44498
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...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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
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.