Click here to Skip to main content
12,954,522 members (54,981 online)
Click here to Skip to main content
Add your own
alternative version


3 bookmarked
Posted 23 Oct 2011

Iranian system encoding standard

, 24 Oct 2011 CPOL
Rate this:
Please Sign up or sign in to vote.
There doesn't seem to be any encoding for the 'Iranian system encoding standard' in .NET
Someone posted a question about how to convert from the Iranian system encoding standard[^] into Unicode using .NET.

I just had a look and this is a really interesting question.
There are a few encodings in .NET that might be derived from the 'Iran System encoding standard', but they don't appear to be as described in the Wikipedia page[^].
708: Arabic (ASMO 708) - different
720: Arabic (DOS) - different
864: Arabic (864) - different
1256: Arabic (Windows) - different 
10004: Arabic (Mac) - not found
20420: IBM EBCDIC (Arabic) - not found
28596: Arabic (ISO) - different

I thought it would be fun to try to write it then:
class IranianSystemEncoding
    static char[] ByteToChar;
    static Byte[][] CharToByte;
    static IranianSystemEncoding()
    static void InitializeData()
        var iranSystem = new int[] { 0x06F0, 0x06F1, 0x06F2, 0x06F3, 0x06F4, 0x06F5, 0x06F6, 0x06F7, 0x06F8, 0x06F9, 0x060C, 0x0640, 0x061F, 0xFE81, 0xFE8B, 0x0621, 0xFE8D, 0xFE8E, 0xFE8F, 0xFE91, 0xFB56, 0xFB58, 0xFE95, 0xFE97, 0xFE99, 0xFE9B, 0xFE9D, 0xFE9F, 0xFB7C, 0xFB7C, 0xFEA1, 0xFEA3, 0xFEA5, 0xFEA7, 0x062F, 0x0630, 0x0631, 0x0632, 0x0698, 0xFEB1, 0xFEB3, 0xFEB5, 0xFEB7, 0xFEB9, 0xFEBB, 0xFEBD, 0xFEBF, 0x0637, 0x2591, 0x2592, 0x2593, 0x2502, 0x2524, 0x2561, 0x2562, 0x2556, 0x2555, 0x2563, 0x2551, 0x2557, 0x255D, 0x255C, 0x255B, 0x2510, 0x2514, 0x2534, 0x252C, 0x251C, 0x2500, 0x253C, 0x255E, 0x255F, 0x255A, 0x2554, 0x2569, 0x2566, 0x2560, 0x2550, 0x256C, 0x2567, 0x2568, 0x2564, 0x2565, 0x2559, 0x2558, 0x2552, 0x2553, 0x256B, 0x256A, 0x2518, 0x250C, 0x2588, 0x2584, 0x258C, 0x2590, 0x2580, 0x0638, 0xFEC9, 0xFECA, 0xFECC, 0xFECB, 0xFECD, 0xFECE, 0xFED0, 0xFECF, 0xFED1, 0xFED3, 0xFED5, 0xFED7, 0xFB8E, 0xFB90, 0xFB92, 0xFB94, 0xFEDD, 0xFEFB, 0xFEDF, 0xFEE1, 0xFEE3, 0xFEE5, 0xFEE7, 0x0648, 0xFEE9, 0xFEEC, 0xFEEB, 0xFBFD, 0xFBFC, 0xFBFE, 0x00A0 };
        ByteToChar = new char[256];
        // ascii first
        for (int i = 0; i < 128; i++) ByteToChar[i] = (char)i;
        // non-ascii
        for (int i = 128; i < 256; i++) ByteToChar[i] = (char)iranSystem[i - 128];
        // ok now reverse
        CharToByte = new Byte[256][];
        for (int i = 0; i < 256; i++)
            char ch = (char)ByteToChar[i];
            var low = ch & 0xff;
            var high = ch >> 8 & 0xff;
            var lowCharToByte = CharToByte[high];
            if (lowCharToByte == null)
                lowCharToByte = new Byte[256];
                CharToByte[high] = lowCharToByte;
            lowCharToByte[low] = (byte)(i);
    public static String GetString(byte[] bytes)
        var sb = new System.Text.StringBuilder();
        foreach (var b in bytes)
        return sb.ToString();
    public static Byte[] GetBytes(string str)
        var mem = new System.IO.MemoryStream();
        foreach (var ch in str)
            var high = ch >> 8 & 0xff;
            var lowCharToByte = CharToByte[high];
            Byte res = 0;
            if (lowCharToByte != null)
                var low = ch & 0xff;
                res = lowCharToByte[low];
            if (res == 0) res = 0xff;
        return mem.ToArray();

I have no clue if it works or not. My Visual Studio gets confused with left and right when I try to put some of those characters in the source.
This was good fun though.


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Pascal Ganaye
Software Developer (Senior)
France France
I am a French programmer.
These days I spend most of my time with the .NET framework, JavaScript and html.

You may also be interested in...

Comments and Discussions

Question[My vote of 1] my vote of 1 because it doesn't work at all! Pin
Jalal Khordadi14-Jan-15 4:59
memberJalal Khordadi14-Jan-15 4:59 
AnswerRe: [My vote of 1] my vote of 1 because it doesn't work at all! Pin
Pascal Ganaye20-Jan-15 9:01
memberPascal Ganaye20-Jan-15 9:01 
Questionvar in vs 2005 Pin
hamid norouzi23-Jun-13 0:01
memberhamid norouzi23-Jun-13 0:01 
Questionthe type 'var' is unknown in vs 2005 Pin
hamid norouzi22-Aug-12 12:53
memberhamid norouzi22-Aug-12 12:53 
AnswerRe: the type 'var' is unknown in vs 2005 Pin
Pascal Ganaye22-Aug-12 23:11
memberPascal Ganaye22-Aug-12 23:11 
GeneralRe: the type 'var' is unknown in vs 2005 Pin
Babak Bakhshayesh10-Apr-13 6:36
memberBabak Bakhshayesh10-Apr-13 6:36 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web02 | 2.8.170525.1 | Last Updated 24 Oct 2011
Article Copyright 2011 by Pascal Ganaye
Everything else Copyright © CodeProject, 1999-2017
Layout: fixed | fluid