Posts

Showing posts with the label Ascii

C++: Printing ASCII Heart And Diamonds With Platform Independent

Answer : If you want a portable way, then you should use the Unicode code points (which have defined glyphs associated to them): ♠ U+2660 Black Spade Suit ♡ U+2661 White Heart Suit ♢ U+2662 White Diamond Suit ♣ U+2663 Black Club Suit ♤ U+2664 White Spade Suit ♥ U+2665 Black Heart Suit ♦ U+2666 Black Diamond Suit ♧ U+2667 White Club Suit Remember that everything below character 32 in ASCII is a control character . They have a meaning associated with them and you don't have a guarantee of getting a glyph or a behavior there (even though most control characters to have glyphs, although they were never intended to be printable). Still, it's not a safe bet. However, using Unicode needs proper font and encoding support which may or may not be a problem on UNIX-likes. On Windows at least some of the above code points map to the ASCII control character glyphs you're outputting if the console is set to raster fonts (and therefore not supporting Unicode or anything else th...

Convert ASCII Character To X11 Keycode

Answer : This question has an old, wrong answer (from @oldrinb), that oddly has never been challenged. As stated in the comment, you can't use XStringToKeysym to map chars to KeySyms in a general way. It will work for letters and numbers, but that's about it, because the KeySym name happens to map directly for those ASCII characters. For other ASCII characters such as punctuation or space it won't work. But you can do better than that. If you look at <X11/keysymdef.h> you find that for ASCII 0x20-0xFF, the characters map directly to XKeySyms . So, I'd say it's simpler to just use that range of characters directly as KeySyms , and just map the remaining 32 characters to their corresponding KeyCodes . So I'd say the code should more properly be: Display *display = ...; if ((int)c >= 0x20) { XKeysymToKeycode(display, (KeySym)c); } else { ... // Exercise left to the reader :-) } The 'else' clause will require multiple KeyCodes since f...

Converting EBCDIC To ASCII In Java

Answer : If I am interpreting this format correctly you have a binary file format with fixed-length records. Some of these records are not character data (COBOL computational fields?) So, you will have to read the records using a more low-level approach processing individual fields of each record: import java.io.*; public class Record { private byte[] kdgex = new byte[2]; // COMP private byte[] b1code = new byte[2]; // COMP private byte[] b1number = new byte[8]; // DISPLAY // other fields public void read(DataInput data) throws IOException { data.readFully(kdgex); data.readFully(b1code); data.readFully(b1number); // other fields } public void write(DataOutput out) throws IOException { out.write(kdgex); out.write(b1code); out.write(b1number); // other fields } } Here I've used byte arrays for the first three fields of the record but you could use other more suitable types where appropriate (like a short for the first field with rea...