Search code examples
c#globalization

Convert Greek Characters to Terminal Hex Font


I need to Convert greek characters as charmap terminal font hex value. Image

Example how can i convert

string test="ΞΥΔΙ";

to hex value "\0x8D.......and so on.

If will Convert from String to Hex i'm getting wrong hex value

 byte[] ba = Encoding.GetEncoding(1253).GetBytes("ΨΓΣΦ");
        var hexString = BitConverter.ToString(ba);
        MessageBox.Show(hexString);

Example from character 'Ξ' i'm getting 0xCE


Solution

  • You are close:

    1. Change Code Page from Windows (Win-1253) to MS DOS one (737)
    2. If you want to see codes represented as a string, I suggest using Linq and String.Join

    Something like this:

     // Terminal uses MS DOS Code Page which is 737 (not Win-1253)
     byte[] ba = Encoding.GetEncoding(737).GetBytes("ΞΥΔΙ"); 
    
     // Let's use Linq to print out a test
     var hexString = string.Join(" ", ba.Select(c => $"0x{(int)c:X2}"));
    
     Console.Write(hexString);
    

    Outcome:

     0x8D 0x93 0x83 0x88
    

    Please, notice that Ξ has 0x8D code.