Hi, I am trying to read a binary file to update a table. The data is packed, and some of it is contained in one byte as packed decimal. Is there an quick way to convert this data to an integer?
If it is EBCDIC, that would be ideal, because it is just a straight conversion. But I do not recall EBCDIC being used to store hex values using only 0 - 9 and skipping A - F to convert to decimal.
Any body remember the reference to EBCDIC in the old Zork games?
EBCDIC is a text coding like ANSI so I don't think it is relevant to this discussion. Packed decimal - can't remember exactly but obviously it is not ordinary hexadecimal. Apart from anything else it will have a decimal point in it somewhere. I seem to recall it has two numbers per byte, side by side. So 23 is stored in a byte but as 2 and 3 rather than (20+3).
Every mainframe has got utilities that transform data codings so the obvious thing is to run the file through one of those before you try to deal with it. Turn it into external format.
Wow. Blast from my cobol programming past. Packed decimal is not hex. BNPMike is correct. A quick and simple way is to write a little cobol program - packed in, decimal out.
Packed decimal on the IBM allows a large number to be stored in a smaller number of bytes. For example, an EBCDIC number of 2 bytes, such as, 99 would have a hex representation of F9F9 and after packing would be 099F. If this was negative it would be 099D. Depending on how it was packed a positive number could also be 099C which is normally the case. Since as was pointed out, Hex would not come into play in converting this number. You could convert this number by understanding the format of the packed decimal field. There is no explicit decimal in the number that is established by an input/output mask.
Well, I used Blorf's suggestion, and it works fine. The packed data is in only 1 byte and is unsigned. For example, when I grab a byte with 20 hex, vb reads it as 32. By Hex(variable name), it converts it back to 20, and I can put it in the table. Packed decimal is very common on mainframes, and that is what I primarily work on. I have been asked to develope some Access applications and I'm learning vb on the fly, so I appreciate the help.
This site uses cookies to help personalise content, tailor your experience and to keep you logged in if you register.
By continuing to use this site, you are consenting to our use of cookies.