473,387 Members | 1,812 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,387 software developers and data experts.

Hex char / string to Long

Bob
Hi,
It must be easy but I can't see how to this is done.
I mean there will be a plethora of built in methods / properties DEVOTED to
this fundmental need
just waiting to be invoked right?
It must be simple to find. Right in your face so to speak because NOBODY
would have left this out of the latest and greatest framework
implementation.
Then why am I floundering around the net looking for this info?
So OK I give in.
Could someone please point me at the elusive
char.Tohex and string.Tohex functions or do they only exist in my caffeine
addled brain?
What year is this?
Are we still writing hex to decimal code snippets??
Thanks
Bob


Nov 17 '05 #1
5 10958
"Bob" <bo*@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
It must be easy but I can't see how to this is done.
OK.
I mean there will be a plethora of built in methods / properties DEVOTED
to
this fundmental need just waiting to be invoked right?
Not sure if there are a plethora, but there is at least one...
It must be simple to find. Right in your face so to speak because NOBODY
would have left this out of the latest and greatest framework
implementation.
That's right.
Then why am I floundering around the net looking for this info?
Have you tried reading the help?
So OK I give in.
Could someone please point me at the elusive
char.Tohex and string.Tohex functions or do they only exist in my caffeine
addled brain?
string strHex = "FF";
long lngHex = System.Convert.ToInt64(strHex, 16);
What year is this?
It's 2005, for the next couple of months or so...
Are we still writing hex to decimal code snippets??


No.
Nov 17 '05 #2
Umm... your message has a lot of flowery prose talking *around* your
problem, and only a couple word actually describing it. Now, let's try to
get the details.

Are you to convert a string of characters (0-9A-F) into it's equivalent
byte/byte array/int
Or to convert a byte/byte array/int into a string of hex characters?

string sHex ="123ABC";
int i = Int32.Parse(sHex,
System.Globalization.NumberStyles.HexNumber);
byte b = Convert.ToByte(sHex.Substring(0,2));

int iHex = 0x123ABC;
string s = iHex.ToString("X");


--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

"Bob" <bo*@nowhere.com> wrote in message
news:#V**************@TK2MSFTNGP15.phx.gbl...
Hi,
It must be easy but I can't see how to this is done.
I mean there will be a plethora of built in methods / properties DEVOTED to this fundmental need
just waiting to be invoked right?
It must be simple to find. Right in your face so to speak because NOBODY
would have left this out of the latest and greatest framework
implementation.
Then why am I floundering around the net looking for this info?
So OK I give in.
Could someone please point me at the elusive
char.Tohex and string.Tohex functions or do they only exist in my caffeine
addled brain?
What year is this?
Are we still writing hex to decimal code snippets??
Thanks
Bob

Nov 17 '05 #3

try

string hexNum = "0ff";
int num = System.Int32.Parse(hexNum,

System.Globalization.NumberStyles.AllowHexSpecifie r);

(elapsed search time, 2 mins 37 secs.)

hth,
Alan.

Nov 17 '05 #4
Bob
Hi All,
Thanks
for your replies;
My main gripe is that such a fundamental need is poorly documented and
implemented. (IMHO)
Try looking up hex in the C# help and see what I mean.
Try looking up 'Convert hex' also. The VB school is adequately served, the
C# ...?
Ever tried
? long.Parse("0xF") in the immediate window?
No Go.
Why ?
Because you are missing the 'well known'
System.Globalization.NumberStyles.HexNumber parameter
(Thanks James)
And even that doesn't work!
Why? because in this situation you leave out the hex specifier!
Fool. Why did you not know that?

I don't mind spending time researching the more esoteric features of C# when
needed, but I begrudge every second spent on something that should be drop
dead simple.
Well, enough said. I'll grab another cup of coffee and rumble back into my
cave.
Thanks again.
Bob


"Bob" <bo*@nowhere.com> wrote in message
news:%2****************@TK2MSFTNGP15.phx.gbl...
Hi,
It must be easy but I can't see how to this is done.
I mean there will be a plethora of built in methods / properties DEVOTED to this fundmental need
just waiting to be invoked right?
It must be simple to find. Right in your face so to speak because NOBODY
would have left this out of the latest and greatest framework
implementation.
Then why am I floundering around the net looking for this info?
So OK I give in.
Could someone please point me at the elusive
char.Tohex and string.Tohex functions or do they only exist in my caffeine
addled brain?
What year is this?
Are we still writing hex to decimal code snippets??
Thanks
Bob

Nov 17 '05 #5
> I don't mind spending time researching the more esoteric features of C#
when
needed, but I begrudge every second spent on something that should be drop
dead simple.
BTW, Bob, that's not C#; it's the .Net Framework CLR, the same for any
language.

And it *is* drop-dead simple to do it. It's just not drop-dead simple to
find the reference to it. The CLR is huge. I spend at least an hour a day in
the MSDN Library, and have been for many years. Still, I don't feel like
I've read that much of it.

Of course, that's why we have communities like this! :-D

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A watched clock never boils.

"Bob" <bo*@nowhere.com> wrote in message
news:Oh*************@TK2MSFTNGP09.phx.gbl... Hi All,
Thanks
for your replies;
My main gripe is that such a fundamental need is poorly documented and
implemented. (IMHO)
Try looking up hex in the C# help and see what I mean.
Try looking up 'Convert hex' also. The VB school is adequately served, the
C# ...?
Ever tried
? long.Parse("0xF") in the immediate window?
No Go.
Why ?
Because you are missing the 'well known'
System.Globalization.NumberStyles.HexNumber parameter
(Thanks James)
And even that doesn't work!
Why? because in this situation you leave out the hex specifier!
Fool. Why did you not know that?

I don't mind spending time researching the more esoteric features of C#
when
needed, but I begrudge every second spent on something that should be drop
dead simple.
Well, enough said. I'll grab another cup of coffee and rumble back into my
cave.
Thanks again.
Bob

Nov 17 '05 #6

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

Similar topics

4
by: jagmeena | last post by:
Hello, I am sure this problem has been addressed before, however, I could'nt get a suitable solution to my problem. Hence I am posting here. Thanks a lot for all your help. The code I have is ...
1
by: Matt Garman | last post by:
What is the "best" way to copy a vector of strings to an array of character strings? By "best", I mean most elegantly/tersely written, but without any sacrifice in performance. I'm writing an...
13
by: mike79 | last post by:
Hello all, I am a newbie to C, so please bear with me :) I need to create an array in a function (a local variable) with size of 1MB. Since local variables get stored on the stack, at...
4
by: Pokerkook | last post by:
Hello, If anybody could help me with this I would greatly appreciate it. Or at least tell me why I get the output of this garbage: 49 49 10 49 52
4
by: Erich Neuwirth | last post by:
I am calling a function in a DLL from VB6, and I need to convert the code to VB.NET. The function in the DLL is written in C and returns a char * By googling around I found that the way to handle...
33
by: Jordan Tiona | last post by:
How can I make one of these? I'm trying to get my program to store a string into a variable, but it only stores one line. -- "No eye has seen, no ear has heard, no mind can conceive what God...
33
by: Mark P | last post by:
A colleague asked me something along the lines of the following today. For some type X he has: X* px = new X; Then he wants to convert px to a char* (I'm guessing for the purpose of...
18
by: Pedro Pinto | last post by:
Hi there once more........ Instead of showing all the code my problem is simple. I've tried to create this function: char temp(char *string){ alterString(string); return string;
11
by: mwebel | last post by:
Hi, i had this problem before (posted here and solved it then) now i have the same problem but more complicated and general... basically i want to store the adress of a istream in a char* among...
14
by: rtillmore | last post by:
Hello, I did a quick google search and nothing that was returned is quite what I am looking for. I have a 200 character hexadecimal string that I need to convert into a 100 character string. ...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
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
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...

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.