473,774 Members | 2,147 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Convert Hex String to Long/Decimals?

I have a problem. But on .NET 1.1

My Scenario:
Actually I will have a string of hexadecimals read from a xml file. Then
from the hexadecimals, i will add 1 value whenever i made any modifications.
But just i do not how to get started. It is like an incremental hexadecimals.

I have a string of hex.

string strHex = "0100000000 FF";

I want to convert this Hex to decimals, just like the windows calculate,
when you type FF in Hex and click on Dec radio button, it will change to 255.

I tried string.Format(" {0:d}", strHex);

I tried Convert.ToDecim al or Convert.ToInt64

But i still cannot find a solution?

----

I know how to convert long to hex. Like this.
for (long x = 000000000000; x <= 281474976710655 ; x++)

{

Console.WriteLi ne(string.Forma t("{0:x12}", x));

Console.ReadLin e();

}

But i do not know how to do the opposite? Anyone can help me please?

Thanks.
Nov 17 '05 #1
3 14522
Hi,

you could use this:
int number;
string strHex = "0100000000 FF";
number = Convert.ToInt32 ("FF", 16);
// ..... some operation maybe
// number++
strHex = number.ToString ("X");

This works, but it doesn't output leading zeros.

Christof

"Chua Wen Ching" <Chua Wen Ch***@discussio ns.microsoft.co m> schrieb im
Newsbeitrag news:3A******** *************** ***********@mic rosoft.com...
I have a problem. But on .NET 1.1

My Scenario:
Actually I will have a string of hexadecimals read from a xml file. Then
from the hexadecimals, i will add 1 value whenever i made any
modifications.
But just i do not how to get started. It is like an incremental
hexadecimals.

I have a string of hex.

string strHex = "0100000000 FF";

I want to convert this Hex to decimals, just like the windows calculate,
when you type FF in Hex and click on Dec radio button, it will change to
255.

I tried string.Format(" {0:d}", strHex);

I tried Convert.ToDecim al or Convert.ToInt64

But i still cannot find a solution?

----

I know how to convert long to hex. Like this.
for (long x = 000000000000; x <= 281474976710655 ; x++)

{

Console.WriteLi ne(string.Forma t("{0:x12}", x));

Console.ReadLin e();

}

But i do not know how to do the opposite? Anyone can help me please?

Thanks.

Nov 17 '05 #2
Try the following:

Int64.Parse("01 00000000FF",Sys tem.Globalizati on.NumberStyles .HexNumber)

"Chua Wen Ching" wrote:
I have a problem. But on .NET 1.1

My Scenario:
Actually I will have a string of hexadecimals read from a xml file. Then
from the hexadecimals, i will add 1 value whenever i made any modifications.
But just i do not how to get started. It is like an incremental hexadecimals.

I have a string of hex.

string strHex = "0100000000 FF";

I want to convert this Hex to decimals, just like the windows calculate,
when you type FF in Hex and click on Dec radio button, it will change to 255.

I tried string.Format(" {0:d}", strHex);

I tried Convert.ToDecim al or Convert.ToInt64

But i still cannot find a solution?

----

I know how to convert long to hex. Like this.
for (long x = 000000000000; x <= 281474976710655 ; x++)

{

Console.WriteLi ne(string.Forma t("{0:x12}", x));

Console.ReadLin e();

}

But i do not know how to do the opposite? Anyone can help me please?

Thanks.

Nov 17 '05 #3
Ooops
you should use long instead of int and ToInt64 instead of ToInt32.
otherwise your string value is to big.
My Example would work up to "7FFFFFFF"

Christof

"Christof Nordiek" <cn@nospam.de > schrieb im Newsbeitrag
news:OY******** ******@TK2MSFTN GP14.phx.gbl...
Hi,

you could use this:
int number;
string strHex = "0100000000 FF";
number = Convert.ToInt32 ("FF", 16);
// ..... some operation maybe
// number++
strHex = number.ToString ("X");

This works, but it doesn't output leading zeros.

Christof

"Chua Wen Ching" <Chua Wen Ch***@discussio ns.microsoft.co m> schrieb im
Newsbeitrag news:3A******** *************** ***********@mic rosoft.com...
I have a problem. But on .NET 1.1

My Scenario:
Actually I will have a string of hexadecimals read from a xml file. Then
from the hexadecimals, i will add 1 value whenever i made any
modifications.
But just i do not how to get started. It is like an incremental
hexadecimals.

I have a string of hex.

string strHex = "0100000000 FF";

I want to convert this Hex to decimals, just like the windows calculate,
when you type FF in Hex and click on Dec radio button, it will change to
255.

I tried string.Format(" {0:d}", strHex);

I tried Convert.ToDecim al or Convert.ToInt64

But i still cannot find a solution?

----

I know how to convert long to hex. Like this.
for (long x = 000000000000; x <= 281474976710655 ; x++)

{

Console.WriteLi ne(string.Forma t("{0:x12}", x));

Console.ReadLin e();

}

But i do not know how to do the opposite? Anyone can help me please?

Thanks.


Nov 17 '05 #4

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

Similar topics

4
20150
by: Dean G | last post by:
I need to compare two values. one from a text field 'bid' and the other from a field in an sql server database 'maxbid'. The problem is the column in the database has decimal as its data type and i'm getting a type mismatch. does anyone know how to convert 'bid' into decimal from varchar? the field datatype doesnt necessarily have to be decimal although i need two decimal places so it cant be an int. Thanks, Dean
4
3635
by: Eric Lilja | last post by:
Hello, I've made a templated class Option (a child of the abstract base class OptionBase) that stores an option name (in the form someoption=) and the value belonging to that option. The value is of the type the object is instantiated with. In my test program I have Option<std::string> and Option<long>. Here's the code for OptionBase and Option along with a small helper function. In the code are comments describing my problem, look closely...
3
2542
by: David Lozzi | last post by:
Howdy, ISSUE 1: See issue 2 below. I have a distance calculator on my site which works great. However, the users need to sort by distance, which make sense. I'm not sure how to do it other than like this. With the returning query include the distance from origin. Here's my dilemma, I have the script working great in VB which provides the distance, but that is not sortable, but when I port it over to TSQL I get differing results. Here is the...
1
2306
by: Mark Hollander | last post by:
Hi All, Could you please help me convert this code so that it will run in VB.NET Thank You Mark Hollander Private Type USER_INFO Name As String
5
27686
by: 2redline | last post by:
I am trying to write a query in access that will pull results that are in the database in a text field and convert to where I can get a average including decimals. Any Ideas? -----------------------Start SQL-------------------------------------- SELECT AVG(CAST(dbo_sur_response_answer.answer_text AS int)) AS avg_correct FROM (dbo_sur_response_answer INNER JOIN dbo_sur_subitem
4
4523
by: Edwin Knoppert | last post by:
In my code i use the text from a textbox and convert it to a double value. I was using Convert.ToDouble() but i'm used to convert comma to dot. This way i can assure the text is correct. However it seems this convert is determined by the local settings and comma is indeed used as decimal separator. Is there another way to convert a dotted value to a double variable? Like 1234.5 and not 1234,5
52
1565
by: FAQ server | last post by:
----------------------------------------------------------------------- FAQ Topic - How do I convert a Number into a String with exactly 2 decimal places? ----------------------------------------------------------------------- When formatting money for example, to format 6.57634 to 6.58, 6.5 to 6.50, and 6 to 6.00? Rounding of x.xx5 is uncertain, as such numbers are not represented exactly.
7
8758
by: Dag Sunde | last post by:
I want to use the format-number function to output a number with a specific number of decimals, based on the content of a node... Is there any smart way to generate differnet strings based on a node-value? if decimals = 0, I want "###,###" decimals = 1, I want "###,###.0" decimals = 2, I want "###,###.00" decimals = n, I want "###,###.000..n"
38
2724
by: ssecorp | last post by:
char* reverse(char* str) { int length = strlen(str); char* acc; int i; for (i=0; i<=length-1; i++){ acc = str; } return acc; }
0
9621
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9454
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10267
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9914
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
6717
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5355
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 last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4012
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
3611
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
2852
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 can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.