我需要存储以下内容:
1.一个Byte
中最多8个Boolean
值
(U)Int32
中最多32个Boolean
值(U)Int64
中最多64个Boolean
值Byte
是否比Char
更适合8位?
对于32/64位,我应该使用signed
还是unsigned
?
是否有一个特定于Delphi的代码示例可以将Byte
/Integer
转换为Boolean
数组,或者将Boolean
数组转换为Byte
/Integer
数组?例如,可以将第N项设置为true/false,例如:
SetItemBoolean(ItemNumber: Integer; Value: Boolean);
我发现了一些东西可以从一个Char
转换成一个Boolean
数组,我只是想知道如何对Byte
/Integer
进行转换,这样我就可以支持更多的Boolean
值。
https://ibeblog.com/2010/08/20/delphi-binary-data-storage/
3条答案
按热度按时间vu8f3i0k1#
Delphi 为此提供了
TIntegerSet
,它具有整数的大小,因此可以在其上进行转换。对于一个字节中的8位,可以用类似的方式声明
TByteSet
:并将其转换为Byte变量或从Byte变量转换。
e4eetjau2#
此类型实现任意大小的位集。
vojdkbi03#
这是一个简单的二进制逻辑。你可以用任何数字类型存储数据,但我建议使用无符号类型。这里是BYTE类型的示例,但你可以对任何(UInt16,UInt32,UInt64)写相同的内容,只需改变AStorage参数的类型:
在这种情况下,每个布尔值只使用1个比特。