1

ASCII characters are from 0 to 127 but only some numbers are printable characters. 32 of them are control characters and are not printable. Is there any way to assign any character to that hex values of 32 character? so that i can print all the 127 characters. I don't want UTF since it take 2 bytes per some characters. I want all characters from 0 to 255 for one byte per character. I'm planning to save the file in ANSI format.

By the way I'm developing this program in Python.

Kindly advice.

Code

Text

Thomas Dickey
  • 51,086
  • 7
  • 70
  • 105
Shane Studio
  • 31
  • 1
  • 5

1 Answers1

0

It is possible. Each text file is also a binary file. Therefore all characters, whether they printable or not, are represented by a number [0..255]. If you read the file char by char, you can always retrieve that number with ord(char).

Instead of a standard UTF-8 text interpretation (Python uses UTF-8 as internal representation), you can use your own private MYASCII table that translates the ordinal number to the character you want.

Writing to file is similar: Suppose you have a 'strange' character 'я', you can write the ordinal value of its place in your own MYASCII table then instead of writing that character, you write the ordinal number to file with chr(num).

This way you define your own 'encodings'. That is, how you would interpret the numbers [0 .. 255] in the text file. However, you always need your own MYASCII table to interpret the file. For any program without that table, that is for example any external text editor, it will be displayed as if it where ANSI.

Ronald
  • 2,930
  • 2
  • 7
  • 18
  • I used latin characters to replace the 31 controllable characters but when saving on text editor in ANSI format. unable to identify the characters. Any solution? – Shane Studio Jun 29 '20 at 16:21
  • I have uploaded the screenshots of the code and text file after saving the character. Kindly check it. It's updated in the question above. – Shane Studio Jun 29 '20 at 17:13
  • I don't want to be difficult, but it really is best to post your code as text. This way I have to type it all over :-( – Ronald Jun 29 '20 at 20:56