DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C (http://www.daniweb.com/forums/forum118.html)
-   -   Algorithm for EBCDIC to ASCII Conversion (http://www.daniweb.com/forums/thread151486.html)

smnadig Oct 16th, 2008 4:24 am
Algorithm for EBCDIC to ASCII Conversion
 
Hello,

The Hexadecimal value of EBCDIC has to be converted to corresponding character as the user inputs it.

The following table shows the hexadecimal value of characters in ASCII and EBCDIC.
Can anybody help me with an efficient C-Algorithm for this conversion?

Char----Deci-------Hex.ASCII---Hex.EBCDIC
A ------65---------41------------- C1
B-------66---------42-------------C2
C-------67---------43-------------C3
D-------68 ---------44-------------C4
E-------69----------45-------------C5
F-------70----------46-------------C6

Thank you very much in advance.

Regards,
Sahana

Sci@phy Oct 16th, 2008 5:58 am
Re: Algorithm for EBCDIC to ASCII Conversion
 
You could write your hex-to-deci function, and then you can simply write
char a = hex-to-deci-function(hex_num)

Narue Oct 16th, 2008 10:19 am
Re: Algorithm for EBCDIC to ASCII Conversion
 
>Can anybody help me with an efficient C-Algorithm for this conversion?
printf directly supports printing characters, decimal, and hexadecimal, so that's easy. Converting between ASCII and EBCDIC is also easy and highly efficient if you use two conversion tables:
unsigned char ascii[] = {
  /* All characters in ASCII */
};

unsigned char ebcdic[] = {
  /* All characters in EBCDIC */
};

unsigned char to_ascii ( unsigned char c )
{
  return ascii[c];
}

unsigned char to_ebcdic ( unsigned char c )
{
  return ebcdic[c];
}

smnadig Dec 29th, 2008 1:22 am
Re: Algorithm for EBCDIC to ASCII Conversion
 
Thank you.

Regards,
Sahana

ArkM Dec 30th, 2008 6:59 am
Re: Algorithm for EBCDIC to ASCII Conversion
 
ASCII-EBCDIC Chart:
http://www.natural-innovations.com/c...ciiebcdic.html


All times are GMT -4. The time now is 10:34 pm.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC