/*rexx hexus: HEX to/from Character Conversion */ cls; /*programmer David McRitchie, "The REXX Macros Toolbox", Dec 07, 1990*/ say " HEX to/from Character conversion ------------------- HEXUS" say " written by David McRitchie in REXX " say " For conversion to hex C2X() use X followed by char string" say " Uppercase text to hex C2X() use H followed by char string" say " For conversion to char X2C() use C followed by hex string" say " Use R to clear screen and recall last entry" say "-------- Three Examples Follow and then it's your turn ---------" push "X hex this "||DATE('J') push "H hex this "||DATE('J') str="date: " || DATE('U') TIME('N') ||" ";st2="C "||c2x(str) push st2 i = 0; str="seed";say " "; do forever say 'enter C, H, or X conversion, or blank to quit, on next line> '; laststr = str parse pull str op = SYSCAPS(substr(str,1,1)) if op = " " then return(0); if op = "R" then , do; str=laststr;cls; op = SYSCAPS(substr(laststr,1,1));end; say str; if op = "C" then , do; jj=verify(substr(str,3),'0123456789ABCDEFabcdef') if jj\=0 then do; c=substr(substr(str,3),jj,1) nstr = '***ERROR*** char('||c||') in pos.' jj , 'of string is not a hex digit' end else if length(str) - trunc(length(str) / 2)*2 = 1 then , nstr= '***ERROR*** even number of digits required' else do; nstr=X2C(substr(str,3)); say scatter(nstr); end end else if op ="H" then , do; str=SYSCAPS(str) nstr=C2X(SYSCAPS(substr(str,3))); say , "--H-- Conversion to uppercase, before conversion to hex" say scatter(substr(str,3)) end else if op ="X" then do; nstr=C2X(substr(str,3)); say scatter(substr(str,3)) end else do;say "Op code """ op """ unknown -- must be X, H, C, or R" nstr="-------------invalid---------------";end; say "= "||nstr; say " " end; syscaps: procedure uppercase = "ABCDEFGHIJKLMNOPQRSTUVWXYZ" lowercase = "abcdefghijklmnopqrstuvwxyz" arg argg argg = translate(argg,uppercase,lowercase) return argg scatter: procedure; parse arg str; j=0; str1='> '; do while (j <= length(str)); j=j+1; str1=str1||' '||substr(str,j,1); end; return str1; 