如何解压十进制转换回COMP-3? [英] How to convert unpacked decimal back to COMP-3?

查看:900
本文介绍了如何解压十进制转换回COMP-3?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我曾问一个有关转换COMP领域,对此我没有得到任何答案的问题。

I had asked a question about converting COMP fields, for which I did not get any answer.

我希望堆栈溢出​​可以帮助我在这个问题上。

I hope stack-overflow can help me on this question.

我成功地转换COMP-3小数。我需要你在把解压后的小数回COMP-3,在任何高级编程语言的帮助,但最好是在Java或C#.NET。

I succeeded in converting COMP-3 to decimal. I need your help in converting the unpacked decimal back to COMP-3, in any high level programming language, but preferably in Java or c#.net.

推荐答案

在压缩十进制-123表示为X'123d(最后​​nyble C,D或F的符号) 。
一来处理压缩十进制最简单的方法是简单地将字节
转换为十六进制字符串(反之亦然根据需要),然后使用普通的字符串操作。这可能不是最有效的,但它很容易实现。

In packed decimal -123 is represented as X'123d' (the last nyble c,d or f being the sign). One of the simplest ways to handle packed decimal is to simply convert the bytes to a hex string (or vice versa as required) then use normal string manipulation. This may not be the most efficient but it is easy to implement.

所以要一个整数(值)转换为压缩十进制大致是(注:我没有测试过的代码)

So to convert a Integer (value) to packed decimal is roughly (note: I have not tested the code)

String sign = "c";
if (value < 0) {
    sign = "d";
    value = -1 * value;
}
String val = value + "d"

byte[] comp3Bytes = new BigInteger(val, 16).toByteArray();



以下是转换到/从COMP3
要检索压缩十进制一些示例代码字节数组看到的 =htt​​p://record-editor.svn.sourceforge.net/viewvc/record-editor/Source/JRecord/src/net/sf/JRecord/Common /Conversion.java?revision=3&view=markup相对=nofollow> http://record-editor.svn.sourceforge.net/viewvc/record-editor/Source/JRecord/src/net/sf/JRecord /Common/Conversion.java?revision=3&view=markup

和设置压缩十进制见
setField中的 http://record-editor.svn.sourceforge.net/viewvc/record-editor/Source/JRecord/src/net/sf/JRecord/Types/TypePackedDecimal.java?revision=3&view=markup

这两个程序需要一个字节数组,起始位置,无论是场上位置的长度。

both routines take an array of bytes, a start position and either a length of a field position.

有这样的网站上(JRanch我认为有做转换以及代码),做一些使用Google的其他例子。

There are other examples of doing this on the web (JRanch I think has code for doing the conversion as well), do a bit of googling.

这篇关于如何解压十进制转换回COMP-3?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆