Anjali
Anjali

Reputation: 19

reading packed hexadecimal data from mainframe and converting it into decimal format

I am doing a project on converting the packed hexadecimal data of mainframes to decimal / human readable format using Java. But the data in the file is like:

00011111112       201343    /…æ     
          &c                                               ï%                                                               “*   œ“fæ     —æ          r<   Ìð    
Œ    êŒ000000 000000          q@00000000                  ð                                                   
00011111112       201345    àr<         
          ™                                                                                                                 r<   Ìð     †          Ë…ð   Ë<    Êð    àã000000 000000          q00000000      @            %                                                   
00011111112       201346     Œ                ì                                                                                                                Ë…ð   Ë<         %          é-   ÅÇ    …e*    Äæ000000 000000          ræ00000000   @   Œ            

I don't know how to convert that to the decimal format using Java. I am using `wing for the UI part.

Can anyone help and provide me with any algorithm or working code?

This is the screenshot of a sample set of data where the first line represents the packed hexadecimal data. next 2 lines represents the converted data.

Upvotes: 1

Views: 1857

Answers (2)

Joop Eggen
Joop Eggen

Reputation: 109567

Maybe you mean packed binary coded decimals, BCD.

As you know a byte is 8 bits, representable in base 16, hexadecimal as two hex digits 0-9,A-F. BCD now codeds a number string as 1234, a string with hex bytes 31, 32, 33, 34 packed as 12, 34.

boolean fromBCD(byte ch) {
   (ch & 0xF) < 10 && ((ch >> 4) & 0xF) < 10;
}

int fromBCD(byte ch) {
   (ch & 0xF) + 10 * ((ch >> 4) & 0xF)
}

Upvotes: 0

Tassos Bassoukos
Tassos Bassoukos

Reputation: 16142

You will need to know what the format is, and work using bytes. Use InputStream and not Reader, remember that mainframes may use EBCDIC instead of ASCII, and mey $DEITY help your soul.

In all seriousness, you will need to know the wire format of what you want to do. Find that first, it's documented somewhere. (Hopefully; it's a mainframe, so who knows).

Upvotes: 1

Related Questions