testsc
testsc

Reputation: 71

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

Upvotes: 2

Views: 364

Answers (2)

Dmitrii Bychenko
Dmitrii Bychenko

Reputation: 186833

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.

Upvotes: 1

babu646
babu646

Reputation: 1001

Your implementation is actually ok from what I've tested.

I just used the Windows calculator and the Wikipedia 1253 encoding table.

I searched for the 'Ξ' character, and although I'm clueless on Greek characters, a simple search shows that the character indeed matches 0xCE (the font looks funky to me, but the browser seems to like it).

enter image description here

Upvotes: 0

Related Questions