Click here to Skip to main content
16,007,472 members
Home / Discussions / C#
   

C#

 
AnswerRe: 8086 assembler Pin
Dave Kreskowiak22-Oct-11 11:36
mveDave Kreskowiak22-Oct-11 11:36 
AnswerRe: 8086 assembler Pin
Luc Pattyn22-Oct-11 13:22
sitebuilderLuc Pattyn22-Oct-11 13:22 
GeneralRe: 8086 assembler Pin
Paul Conrad23-Oct-11 9:16
professionalPaul Conrad23-Oct-11 9:16 
AnswerRe: 8086 assembler Pin
Luc Pattyn23-Oct-11 9:42
sitebuilderLuc Pattyn23-Oct-11 9:42 
GeneralRe: 8086 assembler Pin
Paul Conrad23-Oct-11 9:55
professionalPaul Conrad23-Oct-11 9:55 
Questionconvert unicode to iransystem Pin
mersad0022-Oct-11 6:33
mersad0022-Oct-11 6:33 
AnswerRe: convert unicode to iransystem Pin
BobJanova23-Oct-11 22:29
BobJanova23-Oct-11 22:29 
AnswerRe: convert unicode to iransystem Pin
Pascal Ganaye23-Oct-11 23:05
Pascal Ganaye23-Oct-11 23:05 
I just had a look and this is a really interesting question.
There are a few encoding 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:
C#
class IranianSystemEncoding
{
    static char[] ByteToChar;
    static Byte[][] CharToByte;

    static IranianSystemEncoding()
    {
        InitializeData();
    }

    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)
        {
            sb.Append(ByteToChar[b]);
        }
        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;
            mem.WriteByte(res);
        }
        return mem.ToArray();
    }
}


I have not clue if it works or not. My visual studio get confused with left and right when I try to put some of those characters in the source.
This was good fun though.
I posted this into [Tips] for reference.
AnswerRe: convert unicode to iransystem Pin
Keith Barrow24-Oct-11 1:53
professionalKeith Barrow24-Oct-11 1:53 
QuestionAnimation format Pin
Aleonis22-Oct-11 5:59
Aleonis22-Oct-11 5:59 
QuestionDoes anyone know how to unbox or convert a "1" as a nullable long? Pin
Alaric_22-Oct-11 5:37
professionalAlaric_22-Oct-11 5:37 
AnswerRe: Does anyone know how to unbox or convert a "1" as a nullable long? Pin
Alaric_22-Oct-11 6:03
professionalAlaric_22-Oct-11 6:03 
GeneralRe: Does anyone know how to unbox or convert a "1" as a nullable long? Pin
Alaric_22-Oct-11 6:04
professionalAlaric_22-Oct-11 6:04 
QuestionScope issue declaring a delegate within a static class Pin
dotman121-Oct-11 23:15
dotman121-Oct-11 23:15 
AnswerRe: Scope issue declaring a delegate within a static class Pin
dotman121-Oct-11 23:33
dotman121-Oct-11 23:33 
QuestionAsync Socket Receive Pin
Richard Andrew x6421-Oct-11 6:48
professionalRichard Andrew x6421-Oct-11 6:48 
AnswerRe: Async Socket Receive Pin
Eddy Vluggen21-Oct-11 9:04
professionalEddy Vluggen21-Oct-11 9:04 
AnswerRe: Async Socket Receive Pin
TheGreatAndPowerfulOz21-Oct-11 9:20
TheGreatAndPowerfulOz21-Oct-11 9:20 
AnswerRe: Async Socket Receive Pin
jschell21-Oct-11 10:59
jschell21-Oct-11 10:59 
GeneralRe: Async Socket Receive Pin
Richard Andrew x6421-Oct-11 11:14
professionalRichard Andrew x6421-Oct-11 11:14 
GeneralRe: Async Socket Receive Pin
jschell21-Oct-11 12:15
jschell21-Oct-11 12:15 
GeneralRe: Async Socket Receive Pin
Richard Andrew x6421-Oct-11 17:55
professionalRichard Andrew x6421-Oct-11 17:55 
QuestionMIME Attachment Names containing Extended Characters Fails Pin
Chadwick Posey21-Oct-11 4:39
Chadwick Posey21-Oct-11 4:39 
AnswerRe: MIME Attachment Names containing Extended Characters Fails Pin
Eddy Vluggen21-Oct-11 9:13
professionalEddy Vluggen21-Oct-11 9:13 
GeneralRe: MIME Attachment Names containing Extended Characters Fails Pin
Chadwick Posey21-Oct-11 10:17
Chadwick Posey21-Oct-11 10:17 

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.