Consider this
//I want myVar to equal 0x41
int myVar;
int otherVar = GetItsValue; //returns a decimal 65, 65 is 41 in hex
//now i want to do something like this, obviously doesnt work
myVar = otherVar.ToHex(); //which would ideally be myVar = 0x41
//and then i want to pass myVar to a method as hex
MyMethod(someParam,myVar); // function only accepts hex, its an API call
In other words how do I make that otherVar into a hex?
Thanks.
Nick Z. 7 83717
Try this
string hexstring = otherVar.ToString("X");
To convert back again
int otherVar= int.Parse(hexstring ,
System.Globalization.NumberStyles.HexNumber);
--
Shak
(Houston)
"Nick" <pa*****@optonline.net> wrote in message
news:vh*********************@news4.srv.hcvlny.cv.n et... Consider this
//I want myVar to equal 0x41 int myVar;
int otherVar = GetItsValue; //returns a decimal 65, 65 is 41 in hex
//now i want to do something like this, obviously doesnt work myVar = otherVar.ToHex(); //which would ideally be myVar = 0x41
//and then i want to pass myVar to a method as hex MyMethod(someParam,myVar); // function only accepts hex, its an API call
In other words how do I make that otherVar into a hex?
Thanks. Nick Z.
How about
otherVar =
int.Parse(otherVar.ToString(X),System.Globalizatio n.NumberStyles.HexNumber);
:) :)
--
-Sijin Joseph http://www.indiangeek.net http://weblogs.asp.net/sjoseph
"Shakir Hussain" <sh**@nodomain.com> wrote in message
news:%2***************@TK2MSFTNGP12.phx.gbl... Try this
string hexstring = otherVar.ToString("X");
To convert back again
int otherVar= int.Parse(hexstring , System.Globalization.NumberStyles.HexNumber);
-- Shak (Houston)
"Nick" <pa*****@optonline.net> wrote in message news:vh*********************@news4.srv.hcvlny.cv.n et... Consider this
//I want myVar to equal 0x41 int myVar;
int otherVar = GetItsValue; //returns a decimal 65, 65 is 41 in hex
//now i want to do something like this, obviously doesnt work myVar = otherVar.ToHex(); //which would ideally be myVar = 0x41
//and then i want to pass myVar to a method as hex MyMethod(someParam,myVar); // function only accepts hex, its an API call
In other words how do I make that otherVar into a hex?
Thanks. Nick Z.
Nick <pa*****@optonline.net> wrote: Consider this
//I want myVar to equal 0x41 int myVar;
int otherVar = GetItsValue; //returns a decimal 65, 65 is 41 in hex
//now i want to do something like this, obviously doesnt work myVar = otherVar.ToHex(); //which would ideally be myVar = 0x41
//and then i want to pass myVar to a method as hex MyMethod(someParam,myVar); // function only accepts hex, its an API call
In other words how do I make that otherVar into a hex?
Other posters have shown you how to convert from an integer to a string
representation. However, I think you're missing something important
here - an int variable just contains a number. It doesn't have any base
associated with it - it's just a number. Saying:
int myVar = 0x41;
is *exactly* the same as
int myVar = 65;
If something claims it requires a hex representation, then chances are
it's a string parameter.
--
Jon Skeet - <sk***@pobox.com> http://www.pobox.com/~skeet
If replying to the group, please do not mail me too
Hi Nick
There are two methods you could use:
int nNumber = 1234;
nNumber.ToString("x");
or
string.Format( "{0:X}", 24 );
(X or x will output hex string). For a more flexible formating you should
use the Convert.ToString(number, base) method.
Some more information plus a snippet is included on my snippets page.
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
C# Ebook at http://www.publicjoe.f9.co.uk/csharp/samples/ebook.html
VB Ebook at http://www.publicjoe.f9.co.uk/vbnet/samples/ebook.html
"Nick" <pa*****@optonline.net> wrote in message
news:vh*********************@news4.srv.hcvlny.cv.n et... Consider this
//I want myVar to equal 0x41 int myVar;
int otherVar = GetItsValue; //returns a decimal 65, 65 is 41 in hex
//now i want to do something like this, obviously doesnt work myVar = otherVar.ToHex(); //which would ideally be myVar = 0x41
//and then i want to pass myVar to a method as hex MyMethod(someParam,myVar); // function only accepts hex, its an API call
In other words how do I make that otherVar into a hex?
Thanks. Nick Z. This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: William C. White |
last post by:
Does anyone know of a way to use PHP /w Authorize.net AIM without using
cURL? Our website is hosted on a shared drive and the webhost company
doesn't installed additional software (such as cURL)...
|
by: Albert Ahtenberg |
last post by:
Hello,
I don't know if it is only me but I was sure that header("Location:url")
redirects the browser instantly to URL, or at least stops the execution of
the code. But appearantely it continues...
|
by: James |
last post by:
Hi,
I have a form with 2 fields.
'A'
'B'
The user completes one of the fields and the form is submitted.
On the results page I want to run a query, but this will change
subject to which...
|
by: Ollivier Robert |
last post by:
Hello,
I'm trying to link PHP with Oracle 9.2.0/OCI8 with gcc 3.2.3 on a Solaris9
system. The link succeeds but everytime I try to run php, I get a SEGV from
inside the libcnltsh.so library.
...
|
by: Richard Galli |
last post by:
I want viewers to compare state laws on a single subject.
Imagine a three-column table with a drop-down box on the top. A viewer
selects a state from the list, and that state's text fills the...
|
by: Albert Ahtenberg |
last post by:
Hello,
I have two questions.
1. When the user presses the back button and returns to a form he filled
the form is reseted. How do I leave there the values he inserted?
2. When the...
|
by: inderjit S Gabrie |
last post by:
Hi all
Here is the scenerio ...is it possibly to do this...
i am getting valid course dates output on to a web which i have designed
....all is okay so far , look at the following web url
...
|
by: Jack |
last post by:
Hi All,
What is the PHP equivilent of Oracle bind variables in a SQL statement, e.g.
select x from y where z=:parameter
Which in asp/jsp would be followed by some statements to bind a value...
|
by: Sandwick |
last post by:
I am trying to change the size of a drawing so they are all 3x3.
the script below is what i was trying to use to cut it in half ... I
get errors.
I can display the normal picture but not the...
|
by: DolphinDB |
last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation.
Take...
|
by: DolphinDB |
last post by:
Tired of spending countless mintues downsampling your data? Look no further!
In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
|
by: ryjfgjl |
last post by:
ExcelToDatabase: batch import excel into database automatically...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: isladogs |
last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM).
In this month's session, we are pleased to welcome back...
|
by: Vimpel783 |
last post by:
Hello!
Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
|
by: ArrayDB |
last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
|
by: PapaRatzi |
last post by:
Hello,
I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
|
by: Faith0G |
last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
| |