Pascal Code Translation Example - Reply42.com

Translates either ASCII to EBCDIC or vice versa.

Provided by Stephen Posey

Howdy,

I also thought you might care to include a Borlandish Pascal version of the translation code to the site, to which end I've appended my unit that uses your tables.

This should compile and work in any of Borland's compilers Turbo Pascal 4 and above, as well as Delphi and any of the compilers that emulate the Borland dialect (FreePascal and CodeWarrior may work, and I think there's an emulation switch in GNU Pascal); the main issues are the Unit syntax and whether the compiler supports structured constants.

Anyways, thanks for a useful resource.

Regards,
Stephen Posey

unit EBCCONV;


interface


function ASCII2EBCDIC(Asc: char): byte;
function EBCDIC2ASCII(EBC: byte): char;


implementation


const
  ASCII_translate_EBCDIC : array [0..255] of Byte =
            (
            $00, $01, $02, $03, $04, $05, $06, $07, $08,
            $09, $0A, $0B, $0C, $0D, $0E, $0F,
            $10, $11, $12, $13, $14, $15, $16, $17, $18,
            $19, $1A, $1B, $1C, $1D, $1E, $1F,
            $40, $5A, $7F, $7B, $5B, $6C, $50, $7D, $4D,
            $5D, $5C, $4E, $6B, $60, $4B, $61,
            $F0, $F1, $F2, $F3, $F4, $F5, $F6, $F7, $F8,
            $F9, $7A, $5E, $4C, $7E, $6E, $6F,
            $7C, $C1, $C2, $C3, $C4, $C5, $C6, $C7, $C8,
            $C9, $D1, $D2, $D3, $D4, $D5, $D6,
            $D7, $D8, $D9, $E2, $E3, $E4, $E5, $E6, $E7,
            $E8, $E9, $AD, $E0, $BD, $5F, $6D,
            $7D, $81, $82, $83, $84, $85, $86, $87, $88,
            $89, $91, $92, $93, $94, $95, $96,
            $97, $98, $99, $A2, $A3, $A4, $A5, $A6, $A7,
            $A8, $A9, $C0, $6A, $D0, $A1, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B, $4B,
            $4B, $4B, $4B, $4B, $4B, $4B, $4B );


  EBCDIC_translate_ASCII: array[0..255] of Byte =
            (
            $00, $01, $02, $03, $04, $05, $06, $07, $08,
            $09, $0A, $0B, $0C, $0D, $0E, $0F,
            $10, $11, $12, $13, $14, $15, $16, $17, $18,
            $19, $1A, $1B, $1C, $1D, $1E, $1F,
            $20, $21, $22, $23, $24, $25, $26, $27, $28,
            $29, $2A, $2B, $2C, $2D, $2E, $2F,
            $2E, $2E, $32, $33, $34, $35, $36, $37, $38,
            $39, $3A, $3B, $3C, $3D, $2E, $3F,
            $20, $2E, $2E, $2E, $2E, $2E, $2E, $2E, $2E,
            $2E, $2E, $2E, $3C, $28, $2B, $7C,
            $26, $2E, $2E, $2E, $2E, $2E, $2E, $2E, $2E,
            $2E, $21, $24, $2A, $29, $3B, $5E,
            $2D, $2F, $2E, $2E, $2E, $2E, $2E, $2E, $2E,
            $2E, $7C, $2C, $25, $5F, $3E, $3F,
            $2E, $2E, $2E, $2E, $2E, $2E, $2E, $2E, $2E,
            $2E, $3A, $23, $40, $27, $3D, $22,
            $2E, $61, $62, $63, $64, $65, $66, $67, $68,
            $69, $2E, $2E, $2E, $2E, $2E, $2E,
            $2E, $6A, $6B, $6C, $6D, $6E, $6F, $70, $71,
            $72, $2E, $2E, $2E, $2E, $2E, $2E,
            $2E, $7E, $73, $74, $75, $76, $77, $78, $79,
            $7A, $2E, $2E, $2E, $5B, $2E, $2E,
            $2E, $2E, $2E, $2E, $2E, $2E, $2E, $2E, $2E,
            $2E, $2E, $2E, $2E, $5D, $2E, $2E,
            $7B, $41, $42, $43, $44, $45, $46, $47, $48,
            $49, $2E, $2E, $2E, $2E, $2E, $2E,
            $7D, $4A, $4B, $4C, $4D, $4E, $4F, $50, $51,
            $52, $2E, $2E, $2E, $2E, $2E, $2E,
            $5C, $2E, $53, $54, $55, $56, $57, $58, $59,
            $5A, $2E, $2E, $2E, $2E, $2E, $2E,
            $30, $31, $32, $33, $34, $35, $36, $37, $38,
            $39, $2E, $2E, $2E, $2E, $2E, $2E);



function ASCII2EBCDIC(Asc: char): byte;
begin
  ASCII2EBCDIC := ASCII_translate_EBCDIC[Ord(Asc)];
end;


function EBCDIC2ASCII(EBC: byte): char;
begin
  EBCDIC2ASCII := Chr(EBCDIC_translate_ASCII[EBC]);
end;


end.

I'm an old retired dinosaur, but back in my day, and still in my day, as I learn some of the newer technologies, us computer geeks are nothing without our reference books. And just when you've mastered one technology, another technology comes along, requiring us too learn all over again. A class? Hah! If you're lucky. Otherwise, the hunt is on, for a good reference book. Much like you came to these code table pages. The boss requires you to do the job - even in the absence of adequate reference. Just the way it is, huh?

The best of the best, if you have to bet on a book ... Well, I'd bet on a nutshell book. Hence ...
Shop for Computer Geek Books are all Nutshell books.
I am sure I have half a dozen of these Nutshell books, around here, somewhere.

It really is awesome the geographic diversity that comes to these pages needing to do code translation. I've had emails from Singapore, Italy, Jordon, China, Argentina, and of course - my home country, the USA. The following are the categories of books visitors to this site are buying from:

Shop for Books on Algorithms

Shop for Books on Cisco Routers

Shop for Books on TCP/IP

Shop for Mike Meyers Network Books

Shop for Books on Network Troubleshooting

I threw in this last category of books "for Dummies", because sometimes all you need to know, is covered in these Dummies books. I was just called upon to do some mySQL. Okay fine, but I already know (or have had experience with) at least 5 other databases ... what 'cha want me to do? "GET" the data. "FIND" the data. I just needed the syntax for mySQL, not a entire course in database. My PHP & mySQL for dummies book served me fine.

Shop for HiTech Books for Dummies

 

ASCII to EBCDIC to BINARY Code Tables

ASCII EBCDIC BINARY code translation
ASCII EBCDIC BINARY code translation

Shop my favorite CD's, Books, and Movies.
Recommended favorites, are always better then a shot in the dark, huh?
--- Linda-reply42

Reply 42:  What about the 42?

Click Here to send me an Email / Feedback
Copyright © 1996-2006 by Linda Fisher. All rights reserved.

Presented by:
Reply42.com's Home

:::: Most Popular [all unrelated] :::: Basal Metabolism Calculator :::: Dec, Hex, ASCII, EBCDIC, Binary, Code Tables ::::
:::: Bipolar Essays :::: Our Pointing Labrador Retrievers :::: Garden Collaborations :::: Bear Paw Ranch Resort ::::
:::: Webmasters: Free Sticky Content ::::