Created
May 1, 2017 03:41
-
-
Save arman-hpp/a3ce2e7acece79a247ce24b50e0703d7 to your computer and use it in GitHub Desktop.
AsciiToEbcdic
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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