sigsag
sigsag

Reputation: 59

Convert hexadecimal EBCDIC to character EBCDIC (iseries AS400)

I've this command that converts a character EBCDIC to Hexadecimal on my Iseries (AS400) and it works perfect.

sprintf((char*)(codeHex),"%02X", input[loop]);   

Now, I would like to do the opposite command, I mean.. from an hexadecimal code, convert it to a character EBCDIC, and move it to a string char. How can I do it?

Now the info that I recieve has this format:

char input[300] ="0x004C0x004F0x00430x004B0x00450x00440x0000..."; 
sprintf((char*)(VariableCharacterEBCDIC),"?..", input[loop]);

Regards,

Upvotes: 1

Views: 2488

Answers (2)

Barbara Morris
Barbara Morris

Reputation: 3674

The C prototypes are in QSYSINC/MIH, members CVTCH and CVTHC.

For RPG, you need to code your own prototypes.

Upvotes: 1

Charles
Charles

Reputation: 23791

Rather than building your own function, why not use the functions built into the MI level of the OS..

Convert Hex to Character (CVTHC)

Convert Character to Hex (CVTCH)

They are easily callable from any language on the IBM i, including C.

Note the naming/description is a little wonky, here's a cheat sheet...
CVTHC - Convert to Hex 'A' => 'C1'
CVTCH - Convert to Character 'C1' => 'A'

The RPGLE prototypes look like so:

dcl-pr tohex extproc('cvthc');                 
  hexresult char(65534) options(*varsize);     
  charinp char(32767) const options(*varsize); 
  charnibbles int(10) value;                   
end-pr;                                        

dcl-pr fromhex extproc('cvtch');               
  charresult char(32767) options(*varsize);    
  hexinp char(65534) const options(*varsize);  
  hexlen int(10) value;                        
end-pr;                                        

So for C, you're passing a couple of char pointers and an integer. I just don't recall the C equivalent of extproc('cvthc')

edit - C prototypes courtesy of Player1st

void cvthc(char* hexresult, char* charinp, int charnibbles); 
void cvtch(char* charresult, char* hexinp, int hexlen);

Upvotes: 3

Related Questions