View previous topic :: View next topic
|
Author |
Message |
Harold Barnes
New User
Joined: 27 Oct 2015 Posts: 33 Location: United States
|
|
|
|
I've built 2 tables, one for EBCDIC to ASCII and the other for ASCII to EBCDIC
strin = "A"
estr = translate(strin,ASC,EBC)
say "estr:" c2x(estr)
I'm expecting:
estr: 41
Instead I get :
estr: C1
So translate is not finding 'C1'x in the EBCDIC table and does not change it.
Thinking that my translate table might be bad (never happens) I manually extract the 'C1'x position from the EBCDIC table.
epos = x2d('c1'x) + 1
say "epos: " epos
epos: 194
aval = substr(EBC,epos,1)
say "aval: c2x(aval)
aval: 41
So my EBCDIC table is good. EBCDIC 'A' is ASCII '41'x
apos = x2d('41'x) + 1
apos: 66
aval = substr(ASC,apos,1)
say "aval:" c2x(aval)
aval: C1
So my ASCII table is good. ASCII '41'x is EBCDIC 'C1'x' (letter A)
Each table is 256 bytes of hex values. All values have corresponding values.
Why doesn't translate find the value? |
|
Back to top |
|
|
Harold Barnes
New User
Joined: 27 Oct 2015 Posts: 33 Location: United States
|
|
|
|
Uploading code. (Attached) |
|
Back to top |
|
|
prino
Senior Member
Joined: 07 Feb 2009 Posts: 1306 Location: Vilnius, Lithuania
|
|
|
|
Harold Barnes wrote: |
...Thinking that my translate table might be bad (never happens)... |
If you're so effing certain of yourself, why do you bother to ask here?
And your translate tables are utter crap, and don't allow for correct round-robin translations. |
|
Back to top |
|
|
Nic Clouston
Global Moderator
Joined: 10 May 2007 Posts: 2455 Location: Hampshire, UK
|
|
|
|
Please do not post attachments - some people are not allowed to download and some do not do it as a security precaution. They are also an interference with rapid browsing of the problem. A simple cut and paste is good enough and more economical. Use the code tags to present code and data. |
|
Back to top |
|
|
Harold Barnes
New User
Joined: 27 Oct 2015 Posts: 33 Location: United States
|
|
|
|
I was being sarcastic about the possibility of me making a mistake.
I found the problem. I expected it to work like an ALC translate but it doesn't.
Assumptions will get you every time.
The ASC table just needed to be generated like this:
ASC = ""
do i = 0 to 255
val = x2c(d2x(i)
ASC = ASC || val
end
So basically I generate a table entry for every ascii value. Seems stupid but that's the way translate() works.
Coding:
atran = transalate("A",ASC,EBC)
..will scan the EBC table and find x'C1' in the x'41' position.
Then it will go to the x'41' position in the ASC table and find x'41' (surprising)
The reverse works as well.
atran = transalate('41'x,EBC,ASC)
..will scan the ASC table and find x'41' in the x'41' position. (surprising)
Then it will go to the x'41' position in the EBC table and find x'C1'
Problem solved. |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
the tables might be good , the translate invocation is wrong
when translating from ascii to ebcdic and/or the other way around it is enough to use the output table
the input translate table when omitted defaults to XRANGE('00'x,'FF'x)
Code: |
ebc = translate(asciidata, cp00367_to_cp01047 )
where cp00367_to_cp01047 could be something along the lines of
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
cp00367_to_cp01047 = "40404040404040404040404040404040"x || , /* 0 */
"40404040404040404040404040404040"x || , /* 1 */
"405A7F7B5B6C507D4D5D5C4E6B604B61"x || , /* 2 */
"F0F1F2F3F4F5F6F7F8F97A5E4C7E6E6F"x || , /* 3 */
"7CC1C2C3C4C5C6C7C8C9D1D2D3D4D5D6"x || , /* 4 */
"D7D8D9E2E3E4E5E6E7E8E9ADE0BD5F6D"x || , /* 5 */
"79818283848586878889919293949596"x || , /* 6 */
"979899A2A3A4A5A6A7A8A9C04FD0A140"x || , /* 7 */
"40404040404040404040404040404040"x || , /* 8 */
"40404040404040404040404040404040"x || , /* 9 */
"40404040404040404040404040404040"x || , /* A */
"40404040404040404040404040404040"x || , /* B */
"40404040404040404040404040404040"x || , /* C */
"40404040404040404040404040404040"x || , /* D */
"40404040404040404040404040404040"x || , /* E */
"40404040404040404040404040404040"x /* F */
/* 0 1 2 3 4 5 6 7 8 9 A B C D E F */
|
also You might consider the quirks of code page handling ( {} different hex values for different code pages ) |
|
Back to top |
|
|
Harold Barnes
New User
Joined: 27 Oct 2015 Posts: 33 Location: United States
|
|
|
|
enrico-sorichetti
Thanks for the reminder to use XRANGE() and for mentioning the default input of TRANSLATE().
Your table coding style is a lot cleaner than mine as well. Thanks for sharing.
Nic Clouston:
I attached the code thinking that it might make it easier for someone to play. I'll avoid in the future. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
Enrico's table has '40'x for non-display characters, but I vaguely recall that some displays (maybe it was IPCS) show non-display characters as 'periods'. as place holders so that you can tell there is something there other than spaces. |
|
Back to top |
|
|
|