Skip to content

Instantly share code, notes, and snippets.

@arman-hpp
Created May 1, 2017 03:41
Show Gist options
  • Save arman-hpp/a3ce2e7acece79a247ce24b50e0703d7 to your computer and use it in GitHub Desktop.
Save arman-hpp/a3ce2e7acece79a247ce24b50e0703d7 to your computer and use it in GitHub Desktop.
AsciiToEbcdic
public static class Ebcdic
{
private static readonly char[] Ar1;
private static readonly char[] Ar2;
static Ebcdic()
{
Ar1 = new[]
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', '¢', '.', '<', '(', '+', '|', '&', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', '!', '$', '*', ')', ';', '¬', '-', '/', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
',', '%', '_', '>', '?', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', '`', ':', '#', '@', '\"', '=',
' ', '!', '\'', '#', '$', '%', '&', '\"', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', ' '
};
Ar2 = new[]
{
'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U',
'V', 'W', 'X', 'Y', 'Z', '[', '\\', ']', '^', '_', '`', 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j',
'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '{', '|', '}', '~',
' ', '!', '\"', '#', '$', '%', '&', '\"', '(', ')', '*', '+', ',', '-', '.', '/', '0', '1', '2', '3',
'4', '5', '6', '7', '8', '9', ':', ';', '<', '=', '>', '?', '@'
};
}
public static string AsciiToEbcdic(string sd)
{
var ebcdic = string.Empty;
foreach (var t in sd)
{
var chr = t;
chr = IsCorrectChar(chr);
ebcdic = ebcdic + chr;
}
return ebcdic;
}
private static char IsCorrectChar(char num)
{
for (var j = 0; j < Ar1.Length; j++)
{
if (num == Ar1[j])
{
return Ar2[j];
}
}
return '\n';
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment