January 14, 2003 at 7:45 am
And the winner is Scorpion_66!! That's exactly what I'm looking for! You get the hero award from our applications staff! Send to gary.fahrlander@zurichna.com
Thanks,
Gary
A good day of work as never killed anyone... But why take the chance?
January 14, 2003 at 8:13 am
Here's the character mapping chart, and of course, I'll send it to the E-mail as well.
Here's the process:
Step 1. Convert the Comp-3 (packed decimal) to a decimal integer zoned format - note: this will occupy more bytes then the original Comp-3 (packed decimal) does
Step 2. Convert the EBCDIC zoned format decimal integer to ASCII on a byte for byte basis.
Step 1 Code.
import java.util.*;
import java.io.*;
public final class HexByte {
private static File input_file;
private static FileInputStream input;
private static File output_file;
private static FileOutputStream output;
private static byte hexbyte;
/**
* Description: base 10 int changed to two 4 bit BitSet's
* @param byte the byte the BitSet's are to be created from
* @return BitSet[] the BitSet's created from the byte
* @exception
*/
private final static BitSet[] bitSetsFromBase10(byte hi) {
BitSet bits[] = new BitSet[2];
bits[0] = new BitSet(4);
bits[1] = new BitSet(4);
int bb = new Integer(hi).intValue();
int m7 = bb / 128;
bb = (bb-(m7*128));
if (m7 > 0) { bits[0].set(3); }
int m6 = bb / 64;
bb = (bb-(m6*64));
if (m6 > 0) { bits[0].set(2); }
int m5 = bb / 32;
bb = (bb-(m5*32));
if (m5 > 0) { bits[0].set(1); }
int m4 = bb / 16;
bb = (bb-(m4*16));
if (m4 > 0) { bits[0].set(0); }
int m3 = bb / 8;
bb = (bb-(m3*8));
if (m3 > 0) { bits[1].set(3); }
int m2 = bb / 4;
bb = (bb-(m2*4));
if (m2 > 0) { bits[1].set(2); }
int m1 = bb / 2;
bb = (bb-(m1*2));
if (m1 > 0) { bits[1].set(1); }
int m0 = bb;
if (m0 > 0) { bits[1].set(0); }
return(bits);
}
/**
* Description: bit settings changed to base 10
* @param BitSet the BitSet the decimal integer is to be created from
* @return bb the int created from the BitSet
* @exception
*/
private final static int intBase10FromBitSet(BitSet bs) {
// bit settings changed to base 10
boolean m0 = bs.get(0);
boolean m1 = bs.get(1);
boolean m2 = bs.get(2);
boolean m3 = bs.get(3);
int bb = 0;
if (m0) { bb = bb + 1; }
if (m1) { bb = bb + 2; }
if (m2) { bb = bb + 4; }
if (m3) { bb = bb + 8; }
return(bb);
}
/**
* Description: bit settings changed to base 10
* @param BitSet the BitSet the zoned format decimal integer is to be created from
* @return bb the int created from the BitSet
* @exception
*/
private final static int intBase10ZonedFromBitSet(BitSet bs) {
boolean m0 = bs.get(0);
boolean m1 = bs.get(1);
boolean m2 = bs.get(2);
boolean m3 = bs.get(3);
int bb = 0;
if (m0) { bb = bb + 1; }
if (m1) { bb = bb + 2; }
if (m2) { bb = bb + 4; }
if (m3) { bb = bb + 8; }
if (bb < 10) {
bb = bb + 240;
} else if (bb == 10) { /* positive */
bb = bb + 240;
} else if (bb == 11) { /* negative */
bb = bb + 208;
} else if (bb == 12) { /* positive */
bb = bb + 240;
} else if (bb == 13) { /* negative */
bb = bb + 208;
} else if (bb == 14) { /* positive */
bb = bb + 240;
} else if (bb == 15) { /* positive */
bb = bb + 240;
}
return(bb);
}
public static void main(String args[]) {
try {
input_file = new File("input.file");
input = new FileInputStream(input_file);
output_file = new File("output.file");
output = new FileOutputStream(output_file);
} catch (Exception e) {
System.out.println("Something went wrong with the files " + e);
}
try {
/* simple 16 bit - 2 bytes packed decimal converted to zoned format decimal integer */
/* 123C (positive) converted to F1F2 F3 or 123D (negitive) converted to F1F2 D3 */
toZoned();
withSign();
} catch (Exception e) {
System.out.println("Something went wrong with reading the file " + e);
}
}
private static byte readByte() throws IOException {
int ch = input.read();
if (ch < 0)
throw new EOFException();
return (byte)(ch);
}
/**
* Description: both sets of 4 bits in an 8 bit byte converted to zoned format decimal integer
*/
private static void toZoned() throws IOException {
hexbyte = readByte();
BitSet these_bits[] = bitSetsFromBase10(hexbyte);
int b1 = intBase10ZonedFromBitSet(these_bits[0]);
output.write(b1);
int b2 = intBase10ZonedFromBitSet(these_bits[1]);
output.write((int)b2);
}
/**
* Description: left most 4 bits in an 8 bit byte converted to zoned format decimal integer
* right most 4 bits in an 8 bit byte converted to zoned format sign
*/
private static void withSign() throws IOException {
hexbyte = readByte();
System.out.println("Read in byte " + hexbyte);
BitSet those_bits[] = bitSetsFromBase10(hexbyte);
int b1 = intBase10FromBitSet(those_bits[0]);
int b2 = intBase10FromBitSet(those_bits[1]);
System.out.println(b1 + " sign byte is " + b2);
if (b2 == 10) { /* positive */
b1 = b1 + 240;
} else if (b2 == 11) { /* negative */
b1 = b1 + 208;
} else if (b2 == 12) { /* positive */
b1 = b1 + 240;
} else if (b2 == 13) { /* negative */
b1 = b1 + 208;
} else if (b2 == 14) { /* positive */
b1 = b1 + 240;
} else if (b2 == 15) { /* positive */
b1 = b1 + 240;
}
output.write((int)b1);
}
}
And Step 2.
private static final int ASCII[] = {
0x0020, 0x0021, 0x0022, 0x0023, 0x0024, 0x0025, 0x0026, 0x0027, 0x0028,
0x0029, 0x002a, 0x002b, 0x002c, 0x002d, 0x002e, 0x002f,
0x0030, 0x0031, 0x0032, 0x0033, 0x0034, 0x0035, 0x0036, 0x0037, 0x0038,
0x0039, 0x003a, 0x003b, 0x003c, 0x003d, 0x003e, 0x003f,
0x0040, 0x0041, 0x0042, 0x0043, 0x0044, 0x0045, 0x0046, 0x0047, 0x0048,
0x0049, 0x004a, 0x004b, 0x004c, 0x004d, 0x004e, 0x004f,
0x0050, 0x0051, 0x0052, 0x0053, 0x0054, 0x0055, 0x0056, 0x0057, 0x0058,
0x0059, 0x005a, 0x005b, 0x005c, 0x005d, 0x005e, 0x005f,
0x0060, 0x0061, 0x0062, 0x0063, 0x0064, 0x0065, 0x0066, 0x0067, 0x0068,
0x0069, 0x006a, 0x006b, 0x006c, 0x006d, 0x006e, 0x006f,
0x0070, 0x0071, 0x0072, 0x0073, 0x0074, 0x0075, 0x0076, 0x0077, 0x0078,
0x0079, 0x007a, 0x007b, 0x007c, 0x007d, 0x007e
};
private static final int EBCDIC[] = {
0x0040, 0x005a, 0x007f, 0x007b, 0x005b, 0x006c, 0x0050, 0x007d, 0x004d,
0x005d, 0x005c, 0x004e, 0x006b, 0x0060, 0x004b, 0x0061,
0x00f0, 0x00f1, 0x00f2, 0x00f3, 0x00f4, 0x00f5, 0x00f6, 0x00f7, 0x00f8,
0x00f9, 0x007a, 0x005e, 0x004c, 0x007e, 0x006e, 0x006f,
0x007c, 0x00c1, 0x00c2, 0x00c3, 0x00c4, 0x00c5, 0x00c6, 0x00c7, 0x00c8,
0x00c9, 0x00d1, 0x00d2, 0x00d3, 0x00d4, 0x00d5, 0x00d6,
0x00d7, 0x00d8, 0x00d9, 0x00e2, 0x00e3, 0x00e4, 0x00e5, 0x00e6, 0x00e7,
0x00e8, 0x00e9, 0x00ad, 0x00e0, 0x00bd, 0x005f, 0x006d,
0x0079, 0x0081, 0x0082, 0x0083, 0x0084, 0x0085, 0x0086, 0x0087, 0x0088,
0x0089, 0x0091, 0x0092, 0x0093, 0x0094, 0x0095, 0x0096,
0x0097, 0x0098, 0x0099, 0x00a2, 0x00a3, 0x00a4, 0x00a5, 0x00a6, 0x00a7,
0x00a8, 0x00a9, 0x00c0, 0x006a, 0x00d0, 0x00a1
};
/**
* Description: Translates a int, either ASCII to EBCDIC or vice versa
* @param int the int to be translated
* @return int the translated int
* @exception
**/
public final static int translateByte(int i) {
String thisCharSet = Config.getCharSet();
if (thisCharSet.equals("EBCDIC")) {
for (int j = 0; j<SIZE; j++) {
if (i == ASCII[j]) {
return EBCDIC[j];
}
}
}
return i;
}
}
Viewing 2 posts - 16 through 16 (of 16 total)
You must be logged in to reply to this topic. Login to reply