.NETGURU
Integer to Hex
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcs' list.


Wally McClure
is there anything in C# that is equivalent to VB.NET Hex() function that converts from an integer, long, short, byte to a string representing the hex equivalent of that number?

Wally
Reply to this message...
 
    
David L. Penton
(16).ToString("x") returns "10"

converts to a string representation of 0x10

(29).ToString("x3") returns "01d"

which is left padded to three characters.

David L. Penton, Microsoft MVP
JCPenney Application Specialist / Lead
"Mathematics is music for the mind, and Music is Mathematics for the
Soul. - J.S. Bach"
Click here to reveal e-mail address

Do you have the VBScript Docs or SQL BOL installed? If not, why not?
VBScript Docs: http://www.davidpenton.com/vbscript
SQL BOL: http://www.davidpenton.com/sqlbol

-----Original Message-----
From: Wally McClure [mailto:Click here to reveal e-mail address]

is there anything in C# that is equivalent to VB.NET Hex() function that
converts from an integer, long, short, byte to a string representing the hex
equivalent of that number?

Wally

Reply to this message...
 
    
Brian W. Spolarich

Question: Okay, so how does one take an input string in hex notation =
and convert back to integer?

Answer: int i =3D Int32.Parse("34A1E9",NumberStyles.HexNumber);

Note that the NumberStyle specified doesn't parse the leading "0x" =
notation style. If you give it that kind of input string you'll get a =
format exception error.

-bws=09

| -----Original Message-----
| From: David L. Penton [mailto:Click here to reveal e-mail address]
| Sent: Wednesday, July 31, 2002 11:02 AM
| To: aspngcs
| Subject: [aspngcs] RE: Integer to Hex
|=20
|=20
| (16).ToString("x") returns "10"
|=20
| converts to a string representation of 0x10
|=20
| (29).ToString("x3") returns "01d"
|=20
| which is left padded to three characters.
|=20
|=20
| David L. Penton, Microsoft MVP
| JCPenney Application Specialist / Lead
| "Mathematics is music for the mind, and Music is Mathematics for the
| Soul. - J.S. Bach"
| Click here to reveal e-mail address
|=20
| Do you have the VBScript Docs or SQL BOL installed? If not, why not?
| VBScript Docs: http://www.davidpenton.com/vbscript
| SQL BOL: http://www.davidpenton.com/sqlbol
|=20
|=20
| -----Original Message-----
| From: Wally McClure [mailto:Click here to reveal e-mail address]
|=20
| is there anything in C# that is equivalent to VB.NET Hex()=20
| function that
| converts from an integer, long, short, byte to a string=20
| representing the hex
| equivalent of that number?
|=20
| Wally
|=20
|=20
| | [aspngcs] member Click here to reveal e-mail address =3D YOUR ID
| | http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT
|=20

Reply to this message...
 
    
Joshua Perry
Just call the Convert.ToString() method. The first parameter is the
number that you want to convert into another base. The second parameter
is the base that you want the number to be converted to, which can be 2,
8, 10, or 16.

Joshua Perry
1-800 CONTACTS, INC.
Information Systems Developer
(801)924-9828
=20

-----Original Message-----
From: Brian W. Spolarich [mailto:Click here to reveal e-mail address]=20
Sent: Wednesday, July 31, 2002 9:43 AM
To: aspngcs
Subject: [aspngcs] RE: Integer to Hex

Question: Okay, so how does one take an input string in hex notation
and convert back to integer?

Answer: int i =3D Int32.Parse("34A1E9",NumberStyles.HexNumber);

Note that the NumberStyle specified doesn't parse the leading "0x"
notation style. If you give it that kind of input string you'll get a
format exception error.

-bws=09

| -----Original Message-----
| From: David L. Penton [mailto:Click here to reveal e-mail address]
| Sent: Wednesday, July 31, 2002 11:02 AM
| To: aspngcs
| Subject: [aspngcs] RE: Integer to Hex
|=20
|=20
| (16).ToString("x") returns "10"
|=20
| converts to a string representation of 0x10
|=20
| (29).ToString("x3") returns "01d"
|=20
| which is left padded to three characters.
|=20
|=20
| David L. Penton, Microsoft MVP
| JCPenney Application Specialist / Lead
| "Mathematics is music for the mind, and Music is Mathematics for the
| Soul. - J.S. Bach"
| Click here to reveal e-mail address
|=20
| Do you have the VBScript Docs or SQL BOL installed? If not, why not?
| VBScript Docs: http://www.davidpenton.com/vbscript
| SQL BOL: http://www.davidpenton.com/sqlbol
|=20
|=20
| -----Original Message-----
| From: Wally McClure [mailto:Click here to reveal e-mail address]
|=20
| is there anything in C# that is equivalent to VB.NET Hex()=20
| function that
| converts from an integer, long, short, byte to a string=20
| representing the hex
| equivalent of that number?
|=20
| Wally
|=20
|=20
| | [aspngcs] member Click here to reveal e-mail address =3D YOUR ID
| | http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT
|=20

| [aspngcs] member Click here to reveal e-mail address =3D YOUR ID
| http://www.asplists.com/asplists/aspngcs.asp =3D JOIN/QUIT

Reply to this message...
 
    
Brian W. Spolarich

    int i =3D 12356789;
    Response.Write("i: " + i.ToString() + "<BR>");
    Response.Write("i(hex): " + String.Format("{0:X}", i));

-----Original Message-----
From: Wally McClure [mailto:Click here to reveal e-mail address]
Sent: Wednesday, July 31, 2002 9:12 AM
To: aspngcs
Subject: [aspngcs] Integer to Hex

is there anything in C# that is equivalent to VB.NET Hex() function that =
converts from an integer, long, short, byte to a string representing the =
hex equivalent of that number?

Reply to this message...
 
 
System.Convert
System.Globalization.NumberStyles
System.Int32
System.String




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification