5

In C# is there a way to encode the extended ascii values (128-255) into their single byte values as shown here: http://asciitable.com/

I've tried using Encoding.UTF8.GetBytes() but that returns multi byte values for the extended codes. I don't need anything beyond 255, but it would be nice to at least support those. I'm trying to send the text data to an Arduino running and LED matrix and want to handle accented letters, without having to deal with multibyte characters.

EDIT: To clarify, the LED matrix has no specific codepage. It's basically whatever I say it is. There's no built in text support in it or the arduino. It's just a dumb 128x8 pixel display and the controller is manually drawing the text pixel by pixel. Therefore, I'm actually providing a font (as a byte array in a header file) to it and can make any character code correspond to any output that I want... so, which codepage to use is not really an issue other than which one will give me full 8-bit characters.

Adam Haile
  • 30,705
  • 58
  • 191
  • 286
  • 1
    Yup... I got the unix timestamp thing working... just manually created the byte array whereas before I was building a string that then got mashed through Encoding.ASCII.GetBytes()... So, now I just need to get extended ASCII working for sending text to the display, not the raw data stuff like timestamps. – Adam Haile Jan 07 '11 at 08:19

3 Answers3

5

Just pass the code page number to the Encoding constructor. If what you linked is the correct "extended ASCII" table, that would be 437.

But IBM437 encoding is uncommon outside of DOS programs and Windows console apps. Otherwise, the standard encoding for Western European languages is ISO-8859-1 (Windows code page 28591) or windows-1252.

dan04
  • 87,747
  • 23
  • 163
  • 198
  • Neither ISO-8859-1, windows-1252 or CP437 are single-byte (8 bits) extended ASCII encoding but rather incompatible ASCII extensions. Unfortunately no single-byte extended ASCII encoding exists but many proprietary adaptations exist. See https://en.wikipedia.org/wiki/Extended_ASCII#ISO_8859_and_proprietary_adaptations – noraj Sep 18 '19 at 21:46
2

You need to know the code page that the LED matrix uses. It is bound to be a standard one like 1252, the Windows code page for Western Europe and the Americas.

        var bytes = Encoding.GetEncoding(1252).GetBytes("Åãrdvárk");
Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
1

The Default encoding should handle that. Or use the ANSI codepage/encoding.

leppie
  • 115,091
  • 17
  • 196
  • 297
  • 1
    Although that will probably work, it would be more robust to use a specific encoding, as the program is communicating with an external unit. – Guffa Jan 07 '11 at 08:26