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.
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.
Extended ASCII means an eight-bit character encoding that includes (most of) the seven-bit ASCII characters, plus additional characters.
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.
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.
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.
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");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With