serandre
- 6th April 2006, 18:07
If you use too much strings (A-Z), you can easy get a 62.5% more space, since only 5/8 of the byte is used for the ASCII chars, this let us with a 3/8 wasted space of a byte that serves nothing.
So a string like this:
"HELLO WORLD LETS WASTE SOME BITS"
that takes 32 bytes (256 bits) could be coded as a 5 bit per ASCII character and ocupies only (160 bits), or 20 bytes !!!!!!
The downside is only that if you need to change the string, you will need to code it again, and once coded it's not possible to read it.
But considering some pics like 12f675 that only have a 1k of memory, having this type of code can save your project.
An example could be some type of REMOTE CONTROL decoder, that uses LOOOOTTTTTs of ASCII chars to show on a LCD the command descriptions, etc.... This takes a loot of memory.
To code the strings just subtract from each char (-65), so a "A" (ASCII 65) char will be coded as 0, B will be 1, etc...
Example:
HELLO --> ASCII 72, 69, 76, 76, 79 will be
HELLO --> CODED 7, 4, 4, 14
BINARY SEQUENCE --> 00111 00010 00010 01110
BYTE SEQUENCE --> $38, $84 $E0
See, the HELLO would take 5 bytes, after coded it took 2 1/2 bytes, and yeat there's a space in the last byte to more 1 char !!!
Hope this idea could be usefull to someone, I'm using it with my remote control project, if not using this type of code it would be impossible to me use a Pic12f675.
So a string like this:
"HELLO WORLD LETS WASTE SOME BITS"
that takes 32 bytes (256 bits) could be coded as a 5 bit per ASCII character and ocupies only (160 bits), or 20 bytes !!!!!!
The downside is only that if you need to change the string, you will need to code it again, and once coded it's not possible to read it.
But considering some pics like 12f675 that only have a 1k of memory, having this type of code can save your project.
An example could be some type of REMOTE CONTROL decoder, that uses LOOOOTTTTTs of ASCII chars to show on a LCD the command descriptions, etc.... This takes a loot of memory.
To code the strings just subtract from each char (-65), so a "A" (ASCII 65) char will be coded as 0, B will be 1, etc...
Example:
HELLO --> ASCII 72, 69, 76, 76, 79 will be
HELLO --> CODED 7, 4, 4, 14
BINARY SEQUENCE --> 00111 00010 00010 01110
BYTE SEQUENCE --> $38, $84 $E0
See, the HELLO would take 5 bytes, after coded it took 2 1/2 bytes, and yeat there's a space in the last byte to more 1 char !!!
Hope this idea could be usefull to someone, I'm using it with my remote control project, if not using this type of code it would be impossible to me use a Pic12f675.