Ebcdic to ascii

Hi,

I want to convert ebcdic values to ascii values. Are there anyany specific c++ libraries with g++ compiler, which can do it ?

gcc version 4.1.2 20080704 (Red Hat 4.1.2-54)

Hello tostay2003,
I have a few to questions pose in response first:-

  • Is this homework/assignment? There are specific forums for these.
  • What have you tried so far?
  • What output/errors do you get?
  • What OS and version are you using?
  • What are your preferred tools? (C, shell, perl, awk, etc.)
  • What logical process have you considered? (to help steer us to follow what you are trying to achieve)

Most importantly, What have you tried so far?

There are probably many ways to achieve most tasks, so giving us an idea of your style and thoughts will help us guide you to an answer most suitable to you so you can adjust it to suit your needs in future.

We're all here to learn and getting the relevant information will help us all.

Regards,
Robin

You could keep it simple...like in this link.
EBCDIC-ASCII-DEMO.C

if you just want to do it you can use dd

The standard C function for doing this is iconv() .

EBCDIC can be more complicated than it looks. "blind" converters like dd and the C code above don't take into consideration some obscure multi-byte integer sequences. (This comes up every time, but can I remember what they're called? No...) Can you give us some context please?

Hi,

I am completely unaware of C++. I am calling C++ code as a small part of my program and completely clueless on conversion of ebcdic to ascii (especially the numeric conversion such as zoned, packed decimals, comp-2, comp-3).

I do not want to write C++ code for conversion, but would like to know if any libraries exists, which i can call for conversion of a numeric fields from ebcdic to ascii.

Packed decimals, thank you, that's the term I was reaching for.

Well, is your input packed decimal? If you don't know, neither do we. Context is important, since the difference between -37 or a handful of illegible control characters is just which interpretation you take.

The terms zoned, packed decimal, comp-2, and comp-3 are not EBCDIC; they are COBOL or PL/1 datatypes (like int, long, float, and double are C datatypes; which are not necessarily ASCII, or UTF-8, or EBCDIC).

Hi Don

Can u pls let me know of any libraries in c++...to convert such cobol output in ebcdic to ascii....i have to convert on selective fields......

I am using g++ compiler on linux

I don't know of any C++ libraries to convert COBOL datatypes to/from C++ datatypes.

As I said before, zoned decimal and packed decimal have nothing to do with ASCII or EBCDIC; they are binary formats.

I assume that you have already googled packed decimal and have read this Wikipedia page on Binary-coded decimal. It should give you all you need to convert packed decimal to a C++ integral type. (And, if you have the right hardware, there are assembly language instructions to do the vast majority of the work for you.)

We need context. It'd be all too easy for us to write a function which uses different types from what you have. Show us some code from around where you need the translation code.

Write a cobol program. Its the easiest way to do it. Besides packed decimal, there are also multiple types of signed fields, and binary fields.

GNU Cobol (formerly OpenCOBOL) | Free Development software downloads at SourceForge.net

Hi Don,

a) Are there any libraries for cobol conversion to ANY other formats?
b) Similarly are there any libraries for ebcdic to ascii

We want to use libraries instead of implementing C++ code for which we do not have much expertise

Thanks & Regards,
Asif

  1. You can search the web as easily as I can.
  2. I already told you you could use iconv() from libc. And bigearsbilly already told you you could use the dd utility. But, as I have repeatedly told you those COBOL data formats are binary; not EBCDIC.

You could always use lookup tables here is a simple shell script to generate two "DAT" files into the "/tmp/" folder and are 256 bytes in size...

You just need to compare byte for byte and convert accordingly or join the two files together and convert bytes 0 to 255 against bytes 256 to 511 and vice-versa.

A simple lookup library of your own...

Needless to say this is in its simplest form but is a starter...

#!/bin/bash
> /tmp/ASCII.DAT
> /tmp/EBCDIC.DAT
character=0
char=""
for character in {0..255}
do
	char=`printf '\\\\x'"%02x" $character`
	printf "$char" >> /tmp/ASCII.DAT
done
dd if=/tmp/ASCII.DAT of=/tmp/EBCDIC.DAT conv=ebcdic
ls -l /tmp/*.DAT
hexdump -C /tmp/ASCII.DAT
hexdump -C /tmp/EBCDIC.DAT
echo ""
echo "You now have two very, VERY basic, 256 byte lookup tables to access."
echo "1) /tmp/ASCII.DAT..."
echo "2) /tmp/EBCDIC.DAT..."
echo ""
exit 0

Results on OSX 10.7.5, default bash terminal...

Last login: Sun Aug  3 10:42:53 on ttys000
AMIGA:barrywalker~> chmod 755 ASC2EBC.sh
AMIGA:barrywalker~> ./ASC2EBC.sh
0+1 records in
0+1 records out
256 bytes transferred in 0.000021 secs (12201612 bytes/sec)
-rw-r--r--  1 barrywalker  wheel  256  3 Aug 11:20 /tmp/ASCII.DAT
-rw-r--r--  1 barrywalker  wheel  256  3 Aug 11:20 /tmp/EBCDIC.DAT
00000000  00 01 02 03 04 05 06 07  08 09 0a 0b 0c 0d 0e 0f  |................|
00000010  10 11 12 13 14 15 16 17  18 19 1a 1b 1c 1d 1e 1f  |................|
00000020  20 21 22 23 24 25 26 27  28 29 2a 2b 2c 2d 2e 2f  | !"#$%&'()*+,-./|
00000030  30 31 32 33 34 35 36 37  38 39 3a 3b 3c 3d 3e 3f  |0123456789:;<=>?|
00000040  40 41 42 43 44 45 46 47  48 49 4a 4b 4c 4d 4e 4f  |@ABCDEFGHIJKLMNO|
00000050  50 51 52 53 54 55 56 57  58 59 5a 5b 5c 5d 5e 5f  |PQRSTUVWXYZ[\]^_|
00000060  60 61 62 63 64 65 66 67  68 69 6a 6b 6c 6d 6e 6f  |`abcdefghijklmno|
00000070  70 71 72 73 74 75 76 77  78 79 7a 7b 7c 7d 7e 7f  |pqrstuvwxyz{|}~.|
00000080  80 81 82 83 84 85 86 87  88 89 8a 8b 8c 8d 8e 8f  |................|
00000090  90 91 92 93 94 95 96 97  98 99 9a 9b 9c 9d 9e 9f  |................|
000000a0  a0 a1 a2 a3 a4 a5 a6 a7  a8 a9 aa ab ac ad ae af  |................|
000000b0  b0 b1 b2 b3 b4 b5 b6 b7  b8 b9 ba bb bc bd be bf  |................|
000000c0  c0 c1 c2 c3 c4 c5 c6 c7  c8 c9 ca cb cc cd ce cf  |................|
000000d0  d0 d1 d2 d3 d4 d5 d6 d7  d8 d9 da db dc dd de df  |................|
000000e0  e0 e1 e2 e3 e4 e5 e6 e7  e8 e9 ea eb ec ed ee ef  |................|
000000f0  f0 f1 f2 f3 f4 f5 f6 f7  f8 f9 fa fb fc fd fe ff  |................|
00000100
00000000  00 01 02 03 37 2d 2e 2f  16 05 25 0b 0c 0d 0e 0f  |....7-./..%.....|
00000010  10 11 12 13 3c 3d 32 26  18 19 3f 27 1c 1d 1e 1f  |....<=2&..?'....|
00000020  40 5a 7f 7b 5b 6c 50 7d  4d 5d 5c 4e 6b 60 4b 61  |@Z.{[lP}M]\Nk`Ka|
00000030  f0 f1 f2 f3 f4 f5 f6 f7  f8 f9 7a 5e 4c 7e 6e 6f  |..........z^L~no|
00000040  7c c1 c2 c3 c4 c5 c6 c7  c8 c9 d1 d2 d3 d4 d5 d6  ||...............|
00000050  d7 d8 d9 e2 e3 e4 e5 e6  e7 e8 e9 ad e0 bd 9a 6d  |...............m|
00000060  79 81 82 83 84 85 86 87  88 89 91 92 93 94 95 96  |y...............|
00000070  97 98 99 a2 a3 a4 a5 a6  a7 a8 a9 c0 4f d0 5f 07  |............O._.|
00000080  20 21 22 23 24 15 06 17  28 29 2a 2b 2c 09 0a 1b  | !"#$...()*+,...|
00000090  30 31 1a 33 34 35 36 08  38 39 3a 3b 04 14 3e e1  |01.3456.89:;..>.|
000000a0  41 42 43 44 45 46 47 48  49 51 52 53 54 55 56 57  |ABCDEFGHIQRSTUVW|
000000b0  58 59 62 63 64 65 66 67  68 69 70 71 72 73 74 75  |XYbcdefghipqrstu|
000000c0  76 77 78 80 8a 8b 8c 8d  8e 8f 90 6a 9b 9c 9d 9e  |vwx........j....|
000000d0  9f a0 aa ab ac 4a ae af  b0 b1 b2 b3 b4 b5 b6 b7  |.....J..........|
000000e0  b8 b9 ba bb bc a1 be bf  ca cb cc cd ce cf da db  |................|
000000f0  dc dd de df ea eb ec ed  ee ef fa fb fc fd fe ff  |................|
00000100

You now have two very, VERY basic, 256 byte lookup tables to access.
1) /tmp/ASCII.DAT...
2) /tmp/EBCDIC.DAT...

AMIGA:barrywalker~> _

Wisecracker, he doesn't actually want EBCDIC, he's just parroting the term... And hasn't answered any of our questions enough for us to have the ability to help him.

This might help with a translation. It was written for COBOL, but could be adapted for other languages as well http://home.comcast.net/~wporter211/realsite/programmer/ascebc.cob.txt

wbport, he doesn't actually want EBCDIC, he's just parroting the term... And hasn't answered any of our questions enough for us to even be able to try to help him.

The person who started this thread hasn't responded to questions raised more than a week ago. This thread is closed.