其实倒是有办法的,关键在于楼主所说的不连续这一项, 可以用这种方法 两个字节,前一个字节 a 表示数值表的索引,后一个字节 b 表示偏差值,首先在文件首部建一个不连续数值表 X ,长度256,那么存入的值可以这样表示 X[a]+b ,但这样仍然只能有65536种变化,也就意味着你的索引数据长度只能小于等于65536, 还有一种方法,压缩,将数据压缩起来,这样原数据应该可以超过1G,在使用的时候取出适当的部分进行解压缩
以上两位真把压缩算法当成"神法"了,一共两个字节,16个Bit,还要压缩?
Elysium(東鱗覀爫),具体怎么做?我往一个二进制文件中写入Filewrite(handle,VALUE,2); VALUE怎么突破65535? -------------------------------------------- 是不是做的文件编码规范不满足需求了,只能改成4个字节了。 不过有一种编码方式是自适应需求的,可以参考一下:uintvar - variable length unsigned integerMany fields in the data unit formats are of variable length. Typically, there will be an associated field that specifies the size of the variable length field. In order to keep the data unit formats as small as possible, a variable length unsigned integer encoding is used to specify lengths. The larger the unsigned integer, the larger the size of its encoding.Each octet of the variable length unsigned integer is comprised of a single Continue bit and 7 bits of payload.To encode a large unsigned integer, split it into 7-bit fragments and place them in the payloads of multiple octets. The most significant bits are placed in the first octets with the least significant bits ending up in the last octet. All octets MUST set the Continue bit to 1 except the last octet, which MUST set the Continue bit to 0.For example, the number 0x87A5 (1000 0111 1010 0101) is encoded in three octets: 1 0000010 1 0001111 0 0100101.The unsigned integer MUST be encoded in the smallest encoding possible. In other words, the encoded value MUST NOT start with an octet with the value 0x80.In the data unit format descriptions, the data type uintvar will be used to indicate a variable length integer field. The maximum size of a uintvar is 32 bits. It will be encoded in no more than five octets. It MUST be present even if its value is zero.以上摘自WAP协议族WSP规范 (WAP-230-WSP)8.1.2,主要意思就是说把要编码的无符号整形数分为n个7bit,除了最后的一个7bit前补0外,其它的前面都补1,表示后面还有连续的字节。
to maozefa(阿发伯) 65536 div 256chr 取他的字符,结果是一位吧,但字符是一些乱码,不过都是可以还原成原来的数值。
To ybbhond(路边卖菜的): 你需要好好补补基础课了。65536 div 256 = 256,256如何存入一个字节中?这个问题与楼主的65536如何存入两个字节完全一样,同样无解。前面已经说过了,两个字节只能表示65536个不同的值,想表示第65537种值是没有可能的,不要再在这上面浪费时间了。
VALUE怎么突破65535?
0 1 2 3 4 5 6 7 8 9 A B C D E F H
FFFF = 十进制 15 * 16^3 + 15*16^2 + 15*16 + 15 = 65535
HHHH = 十进制 16 * 17^3 + 16*17^2 + 16*17 + 16 = ..
11111111 11111111
前8位是底数,后8位是幂,
也就是说,用2字节+一系列算法,把FF FF让计算机理解成FF的FF次方…………
---------------------------------------------------
支持
楼主: 我在给客户做个索引方面的程序.现在2个字节,程序在650M左右,如果4个字节就超出1G了.一张CD光盘刻录不下了.总不至于换DVD吧.这年头还是考虑一下贫下中农吧.
-----------------------------------------------------------------------------------
楼主能把上述言论解释一下吗?
可以用这种方法
两个字节,前一个字节 a 表示数值表的索引,后一个字节 b 表示偏差值,首先在文件首部建一个不连续数值表 X ,长度256,那么存入的值可以这样表示 X[a]+b ,但这样仍然只能有65536种变化,也就意味着你的索引数据长度只能小于等于65536,
还有一种方法,压缩,将数据压缩起来,这样原数据应该可以超过1G,在使用的时候取出适当的部分进行解压缩
VALUE怎么突破65535?
--------------------------------------------
是不是做的文件编码规范不满足需求了,只能改成4个字节了。
不过有一种编码方式是自适应需求的,可以参考一下:uintvar - variable length unsigned integerMany fields in the data unit formats are of variable length. Typically, there will be an associated field that specifies the size of the variable length field. In order to keep the data unit formats as small as possible, a variable length unsigned integer encoding is used to specify lengths. The larger the unsigned integer, the larger the size of its encoding.Each octet of the variable length unsigned integer is comprised of a single Continue bit and 7 bits of payload.To encode a large unsigned integer, split it into 7-bit fragments and place them in the payloads of multiple octets. The most significant bits are placed in the first octets with the least significant bits ending up in the last octet. All octets MUST set the Continue bit to 1 except the last octet, which MUST set the Continue bit to 0.For example, the number 0x87A5 (1000 0111 1010 0101) is encoded in three octets:
1 0000010 1 0001111 0 0100101.The unsigned integer MUST be encoded in the smallest encoding possible. In other words, the encoded value MUST NOT start with an octet with the value 0x80.In the data unit format descriptions, the data type uintvar will be used to indicate a variable length integer field. The maximum size of a uintvar is 32 bits. It will be encoded in no more than five octets. It MUST be present even if its value is zero.以上摘自WAP协议族WSP规范 (WAP-230-WSP)8.1.2,主要意思就是说把要编码的无符号整形数分为n个7bit,除了最后的一个7bit前补0外,其它的前面都补1,表示后面还有连续的字节。
s:string;
a,b:Integer;
begin a:=StrTOInt(edit1.Text) Div 256;
b:=StrToInt(edit1.Text) Mod 256;
s:=s+chr(a)+chr(b);
看下这样行不行
可以存为两个字节
===========================================================================
知不知道65536 div 256是多少?你1字节能放下吗?
如果你你数据只在0..>65535范围的话,你可以:
>65535的数
65536=-1
65537=-2
65538=-3
......
写进磁盘里去,在自己读出时,-1,-2,-3.....就转换一下就好了!
取他的字符,结果是一位吧,但字符是一些乱码,不过都是可以还原成原来的数值。
理论上把所有数据都可以压缩成一个0和一个1
------------------------------------------你们老师就这样教你的?
-(ID-65535)
读出来的时候判断是否是负数,如果为负,则程序转换回去。今天放一下分,看能否成功,前两次都不成功.