View Full Version : Hex to Character Conversion Revisited
Guest.Visitor
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
When converting from char to hex, the source length should be twice the Char input length, not the Char input length. Jim
Guest.Visitor
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
In the article you state: cvthc converts from character value to hexadecimal text (that is, from 'A' to X'C1'). I feel that this may be incorrect. 'A' is the same as x'C1' Is it not correct to state: ... (that is, from 'A' to x'FCF1' or 'C1')
Guest.Visitor
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
I have a need to convert EBCDIC characters to ASCII Hex (A123 = x'41313233'). Can these routines convert among CCSID's? Any other way to do this other than Select/When?
Guest.Visitor
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
Thanks Bob. The cvtch and cvthc functions only work on 0-9, A-F. I need to be able to convert the entire character set, including non-alphanumeric characters (i.e. "-/.#" etc.). Any suggestions?
P.Harkins
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
Bob, Thanks very much, yet again, for this valuable technique. I would like to utilize it now in my auditing. Could you please give a example of the Calc specs used to perform this conversion? I need to take any variable and convert it, as in a program dump which shows both Character and Hexidecimal for the variable. Many, many Thanks, Paul H. Harkins
P.Harkins
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
Phil, Many thanks for the complete example. The convert to and from Hex routines would make great BIFs for IBM in RPGLE. Best Regards, Paul H. Harkins
Guest.Visitor
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
I am trying to go from a 128 hex field to a 64 character field. I assume I would only need part of the code you offered (see below)? What I don't understand is how the fields: szCharVal, szHexVal, nSrcLen and len, inCharVal, ouCharVal, inHexVal, ouHexVal relate to each other? What field would I plug in the 128 hex field and what field would return the 64 character field? THank you. <hr width=50 align=left>Code ('http://www.mcpressonline.com/mc/showcode@@.6b284d8c/13')
hope@f2s.com
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
Simple example attached... <hr width=50 align=left>Code ('http://www.mcpressonline.com/mc/showcode@@.6b284d8c/10')
Konrad
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
Bob, how can I specify a codepage (CCSID) there ? I ask because different codepages mean different characters. For example the hex value X'7C' means in codepage 1141 the value "§" and in codepage 1153 the value "@". BR, Konni
B.Morris
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
The meaning of the data doesn't matter to the API. If you have a byte with the value x'7C', the toHex function will give '7C', no matter how x'7C' might appear if you display it.
R.Cozzi
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
You can use iconv() to convert between CCSIDs and then call cvthc and cvtch to convert between character and hex.
R.Cozzi
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
I don't want to sound rude, but you're missing something. You can convert any of the 256 characters to their 2-character hexadecimal equivalent and back again. There is no restrictions.
R.Cozzi
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
Normally you convert to character from hex and then convert the characters to the CCSID of your choice. Use iconv() to convert the CCSID.
R.Cozzi
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
Did you ask this same question on my rpgiv.com/forum recently? Anyway, the way the two built-in work is as follows: cvtch converts to character from hex. cvthc converts to hex from character. The first parameter of both built-ins is the target. Therefore, parm 1 is the resulting character value in cvtch, and is the resulting hex value in in cvthc. The second parm is obviously the opposite value. The third parameter is ALWAYS the length of the hex data. That is the number of hex "values" or symbols (two for each character being converted) being converted.
MCWebsite.Staff
12-31-1969, 06:33 PM
** This thread discusses the article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **
** This thread discusses the Content article: Hex to Character Conversion Revisited (http://www.mcpressonline.com/index.php?option=com_content&view=article&id=1900) **This is a discussion about Hex to Character Conversion Revisited.<p align='center'><a href=http://www.mcpressonline.com/mc?1@232.1KNKfHX1eQT.17@.6b27ccf2>Click here for the article</a>.</p>
Powered by vBulletin® Version 4.1.5 Copyright © 2013 vBulletin Solutions, Inc. All rights reserved.