Packed Decimal number

A

Arne Garvander

I have some packed decimal data (comp-3) which I have downloaded from an IBM
mainframe. I am looking for some .net code (vb preferred) that will convert
from COMP-3 to a .net value type (integer/long).
I have some code, but my code is broken. I already have EBCDIC to ANSII
conversion working.
Where can I get some good code?
 
C

Cowboy \(Gregory A. Beamer\)

You can get a packed field out quite simply by bit shifting the bytes and
then converting to a decimal value. I do not have a library readily
available. I might be able to find a sample, but I am not certain. Have not
worked with EBCDIC in quite some time.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
 
C

Cowboy \(Gregory A. Beamer\)

Idea is to shift the first four to lower level bits. On the other side, you
have to shift up and then pad by shifting down.

Get first four of byte (shift to lower level bits):

byte byteB = (byteA >> 4) ;

Get second four of packed byte (shift up and then pad):

byte byteC = (byteA << 4) >> 4);

You can also replace the first four bits with an and on 00001111 or byte =
15. An anding version is:

byte byteC = byteA & 0xF;

That should and out the top bits and leave only the four low level bits.

To turn this into a decimal, you have to know how many bytes are before and
after the decimal. You then multiply and divide individual bytes by
multiples of 10.

If the packed field is signed, you have to figure out which bit indicates
signing. On some systems it is the first byte, on others the last. I have
not examined all IBM code pages, so there may be some that use a single bit
for + and -, but I would doubt it.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box!
|
*************************************************
Cowboy (Gregory A. Beamer) said:
You can get a packed field out quite simply by bit shifting the bytes and
then converting to a decimal value. I do not have a library readily
available. I might be able to find a sample, but I am not certain. Have
not worked with EBCDIC in quite some time.

--
Gregory A. Beamer
MVP, MCP: +I, SE, SD, DBA

*************************************************
| Think outside the box! |
*************************************************
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top