将十六进制EBCDIC转换为字符EBCDIC(iseries AS400) [英] Convert hexadecimal EBCDIC to character EBCDIC (iseries AS400)
问题描述
我拥有此命令,可以在我的Iseries(AS400)上将字符EBCDIC转换为十六进制,并且效果很好.
sprintf((char*)(codeHex),"%02X", input[loop]);
现在,我想执行相反的命令,我的意思是..从十六进制代码中,将其转换为字符EBCDIC,然后将其移至字符串char.我该怎么办?
现在我收到的信息具有以下格式:
char input[300] ="0x004C0x004F0x00430x004B0x00450x00440x0000...";
sprintf((char*)(VariableCharacterEBCDIC),"?..", input[loop]);
此致
与其构建自己的功能,不如不使用内置在操作系统MI级中的功能.
可以轻松地从IBM i上的任何语言(包括C)调用它们.
请注意,命名/说明有些古怪,这是备忘单...
CVTHC-转换为十六进制'A'=>'C1'
CVTCH-转换为字符'C1'=>'A'
RPGLE原型如下:
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;
因此对于C,您要传递几个char指针和一个整数.我只是不记得extproc('cvthc')
编辑-C语言原型由Player1st提供
void cvthc(char* hexresult, char* charinp, int charnibbles);
void cvtch(char* charresult, char* hexinp, int hexlen);
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,
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);
这篇关于将十六进制EBCDIC转换为字符EBCDIC(iseries AS400)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!