Search code examples
unicodecharacter-encodingcompressionnotepad++ascii

Text file of 256 bytes with 256 unique characters


I'm doing a data compression project and for this I need to have what the title implies.

I already have the first 128 unique characters (7 bit ASCII), see image below:

enter image description here

Sorry for small representation, you're just gonna have to click it to enlarge it '^-^

What you see in the image are the first 32 control characters (there's enters and whitespace characters in there so that's why it is 3 lines instead of one, but every newline is an unique character) followed by another 96 normal characters for up to a total of 128 unique characters containing what windows reports to be:

enter image description here

This is for 7 bits, all nice and dandy, but i need it for 8 bits. so 256 unique characters... Is there a way to get a text file which is 256 bytes in size which contains 256 unique characters? Much obliged!

EDIT: When asking this question I was confused about encoding and what it meant. So basically, a byte is just 8 times a 1 or 0. What that byte means is up to the encoding to tell. What I needed was a binary file of all combinations of 8 bits. Which CAN be interpreted as text, but it is not necessarily text. It can also be interpreted as something else, like numbers or colors.


Solution

  • You can do something like this in Python:

    b = bytearray(range(256))
    f = open('test.txt','wb')
    f.write(b)
    f.close()
    

    The resulting file has exactly 256 bytes, although it is more accurate to think of it as a binary file rather than a text file.