Convert hexadecimal EBCDIC to character EBCDIC (iseries AS400)

谁说我不能喝 提交于 2020-04-10 06:09:52

问题


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,


回答1:


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);



回答2:


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

For RPG, you need to code your own prototypes.



来源:https://stackoverflow.com/questions/58995801/convert-hexadecimal-ebcdic-to-character-ebcdic-iseries-as400

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!