Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Encode to single byte extended ascii values

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.

like image 742
Adam Haile Avatar asked Jan 07 '11 08:01

Adam Haile


People also ask

How do I type extended ASCII?

On a standard 101 keyboard, special extended ASCII characters such as é or ß can be typed by holding the ALT key and typing the corresponding 4 digit ASCII code. For example é is typed by holding the ALT key and typing 0233 on the keypad.

What encoding is extended ASCII?

Extended ASCII means an eight-bit character encoding that includes (most of) the seven-bit ASCII characters, plus additional characters.

How do I encode an ASCII code?

ASCII encodes characters into seven bits of binary data. Since each bit can either be a 1 or a 0, that gives a total of 128 possible combinations. Each of these binary numbers can be converted to denary number from 0 through to 127. For example 1000001 in binary equals 65 in denary.

Does UTF-8 support extended ASCII?

UTF-8 extends the ASCII character set to use 8-bit code points, which allows for up to 256 different characters. This means that UTF-8 can represent all of the printable ASCII characters, as well as the non-printable characters.


2 Answers

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.

like image 166
dan04 Avatar answered Sep 22 '22 02:09

dan04


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");
like image 22
Hans Passant Avatar answered Sep 19 '22 02:09

Hans Passant