| 01-27-2009, 11:47 PM | #1 |
Hey everyone, i currently have made a save and load code, works perfectly and all. Though, i'm still trying to perfect it. Lets get to the point. My problem is that when i do my base10 conversion i need to put the string length of the converted integers length, to know how far to load. So say i saved 27 with a base 26 system. The code would be.... ZA Though i would need to make it 2ZA 2 = Length of ZA So when loading, the function would check for any number, then decode all the numbers after it of a length of the found number. Sorry, that may sound like gibberish. |
| 01-28-2009, 02:02 AM | #2 |
Why not use the save-load system already in the database? It has the highest compression and allows for customization for security. |
| 01-28-2009, 02:14 AM | #3 | |
Quote:
Because i wanted to make my own, i have read through the codes of pipedreams, and i tested it and like it. Though, what harm can practice do. Anyways do you have a solution to my problem? |
| 01-28-2009, 03:14 PM | #4 |
Usually you use Prefix-Codes for generation Code. A Prefix-Code is a code where every part starts with an unique prefix so you dont have to save where one part ends and another starts. The easiest and fastest prefix-code is of course the block-code, so every part has a fixed size. |
| 01-29-2009, 12:22 AM | #5 |
If i read that correctly, that is what mine is doing, and is what i don't want. |
| 01-29-2009, 12:41 PM | #6 |
Well, you have a prefixcode but it wastes space because you only use 9 different symbols for the first character of each block and your charmap has a lot more than 9 symbols. As I said the easiest way is to make it a Block-Code, so you hava fixed length for each block (the length of each block is saved in the system, not in the code). For example the first value you want to save takes 3 characters, the second value takes 7 and so on. So you just add leading zeros if one block is not long enough. For example you want to save 5 different items: item1, item2, item3, item4, item5 and no item. Then your Blockcode could be something like this: no item: 000 item1: 001 item2: 010 item3: 011 item4: 100 item5: 101 Decoding the string is very fast and easy. You just split the string into the single blocks aggain and decode the blocks. Prefixcodes which are no blockcodes can be useful when you want to save values which have different probabilities. For example you want to save 5 different items: item1, item2, item3, item4, item5 and no item with the following probabilities: no item: 50% item1: 30% item2: 5% item3: 5% item4: 5% item5: 5% Then you could use the following codes (using only the symbols 0 and 1): no item: 0 item1: 10 item2: 1100 item3: 1101 item4: 1110 item5: 1111 As you can see the more likely items have shorter codes and so the average code is shorter as with block-codes. It is also a valid code since no code is a prefix of an other code. For example you could decode the string 110110001111 to the following items by just going from left to right: 1 11 110 1101 -> item3 1 10 -> item1 0 -> no item 0 -> no item 1 11 111 1111 -> item5 One huge drawback is that it is more difficult to encode and decode, you would need to have a table where all the codes are saved. Another hint: Often its better to do all the calculation in a Base-2 System and in the last step encode it to a 2^n system. This way you can save 3 values in 2 chars or something like that and save space. Encoding from Base-2 to Base 2^n is quite fast because you just have to encode Blocks of n Base-2 symbols to one Base-2^n symbol. |
| 01-29-2009, 03:52 PM | #7 | |
Quote:
But binary is really confusing to me. |
| 01-29-2009, 04:05 PM | #8 |
its easy ... you can transform binary blocks of n width easily to base-2^n width 2 => 2^2 = 4 width 3 => 2^3 = 8 / octal width 4 => 2^4 = 16 / hexadecimal example 1111 binary (= 15 in decimal*): "A" in hexadecimal "17" in octal (to easier see this add "0"s to the front "001 111" => "001"=1, "111"=7) "33" in base-4 / quartal whatever... 1000 binary (= 8 decimal) "8" in hexadecimal "10" in octal (help:001 000) "20" in base-4 / quartal whatever... *: 1111 binary = 2^3 + 2^2 + 2^1 + 2^0 = 8 + 4 + 2 + 1 = 15 |
