简体   繁体   English

如何将简单Java字符串转换为带有压缩十进制格式的EBCDIC

[英]How to convert a Simple Java String to EBCDIC with packed decimal format

i have to convert all the data in file to EBCDIC with packed decimal format. 我必须使用压缩十进制格式将文件中的所有数据转换为EBCDIC。

all the data in the file is in simple text format. 文件中的所有数据均为简单文本格式。

As per my knowledge we will need to convert the ASCII to EBCDIC Cp1047 or some other format first and then apply “packed decimal” logic/code.(may be i am wrong) 据我所知,我们将需要先将ASCII转换为EBCDIC Cp1047或其他某种格式,然后再应用“压缩十进制”逻辑/代码。(可能是我错了)

the converted format should be like "C3 C5 40 F0 C9 F8"(ie EBCDIC packed decimal format) 转换后的格式应类似于“ C3 C5 40 F0 C9 F8”(即EBCDIC打包的十进制格式)

Packed Decimal (Comp3 in Cobol) 打包十进制(Cobol中的Comp3)

  • +123 is stored as x'123C' +123被存储为x'123C'
  • -123 is stored as x'123D' -123存储为x'123D'
  • unsigned 123 is x'123F' 无符号123是x'123F'

Do you have a Cobol Copybook ???, if you do, see JRecord Question . 您是否有Cobol Copybook ???,如果有,请参阅JRecord Question JRecord also has JRecord也有

  • Csv to Cobol program (Convert a Csv file to Cobol using a Cobol Copybook) Csv到Cobol程序(使用Cobol Copybook将Csv文件转换为Cobol)
  • Xml-to-Cobol program (Convert a Xml file to Cobol using a Cobol Copybook) Xml-to-Cobol程序(使用Cobol Copybook将Xml文件转换为Cobol)

Alternatives to JRecord are JRecord的替代

  • Cobol2J Cobol2J
  • legstar 腿明星
  • various commercial products 各种商品

Note: I am the author of JRecord 注意:我是JRecord的作者


Converting a number to Packed Decimal is pretty easy and there are a number of ways to do it 将数字转换为压缩十进制非常简单,并且有很多方法可以实现

Convert to String 转换为字符串

one option is 一种选择是

  1. Convert the number to a String 将数字转换为字符串
  2. Add the sign Character to the end of the String 将符号字符添加到字符串的末尾
  3. Convert the String to Bytes (Hex-String) 将字符串转换为字节(十六进制字符串)

Java Code to convert an integer to Packed-Decimal Java代码将整数转换为Packed-Decimal

    String val = Integer.toString(Math.abs(value));
    if (value < 0) {
        val = val.substring(1) + "D"
    } else {
        val += "C";
    }

    byte[] bytes = (new BigInteger(val, BASE_16)).toByteArray();

Similar Question 类似问题

How to convert unpacked decimal back to COMP-3? 如何将解压缩的十进制转换回COMP-3?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM