hex from string

For questions and postings not covered by the other forums
ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

hex from string

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:44 pm

by bitsnz >> Mon, 22 Nov 2004 11:02:45 GMT

Hello All

I have a returned string. The string is a number. i.e. string returned is 53
I need to take this string parse it to a hexadecimal format and then get the appropriate character equivalent.

hence; 53 -> #'53' -> ' S'

I need to get the string (53) into the character format (S). Is there an easier way? otherwise how can i do the above?

Thanks for any help

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: hex from string

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:44 pm

by allistar >> Mon, 22 Nov 2004 22:40:06 GMT

There must be a better way than this, but it works:

vars
string, marker: String;begin

marker := "123456789ABCDEF";
string := "53";
write ((marker.pos(string[1], 1) * 16) + marker.pos(string[2], 1)).Character;
end;

Regards,
Allistar.
--
------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: hex from string

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:44 pm

by allistar >> Tue, 23 Nov 2004 0:04:41 GMT

My code above won't work if one of the characters is a "0". It's not too hard to fix though.

Allistar.
--
------------------------------------------------------------------
Allistar Melville
Software Developer, Analyst allistar@silvermoon.co.nz
Auckland, NEW ZEALAND

Silvermoon Software
Specialising in JADE development and consulting
Visit us at: http://www.silvermoon.co.nz
*NEW* Simple web access to Jade at: www.silvermoon.co.nz/jhp.html ------------------------------------------------------------------

ConvertFromOldNGs
Posts: 5321
Joined: Wed Aug 05, 2009 5:19 pm

Re: hex from string

Postby ConvertFromOldNGs » Fri Aug 07, 2009 12:44 pm

by bitsnz >> Wed, 24 Nov 2004 0:12:13 GMT

Cheers Allistar fpr the reply

I played around and created a string method that does the trick for all hex equivalents. It works like a charm.


Return to “General Discussion”

Who is online

Users browsing this forum: No registered users and 26 guests