[fpc-devel] BitHelpers

Zeljko Avramovic avra at writeme.com
Tue Jul 20 12:47:05 CEST 2021


Here is a patch: https://bugs.freepascal.org/view.php?id=39268

Now it is possible to do this:

MyByte.Bit[1] := true;
MyByte.Nibble[0] := MyByte.Nibble[1];

ToBinString and ToHexString are now extended so by customizing DefaultBitFormatSettings, DefaultBinFormatSettings and DefaultHexFormatSettings you can easily get these outputs:

True.ToTrueFalseString                                   = Укључено
True.ToString('OnState', 'OffState')                     = OnState
True.ToString('Running', 'Stopped', scfUpperCase)        = RUNNING
True.ToString('Ради', 'Не ради')                         = Ради
MyDword.Bit[5].ToTrueFalseString                         = False
MyQword.Bit[MQword.MaxBit].ToString(scfUpperCase)        = FALSE
MyDword.Bit[5].ToOneZeroString                           = 1
MyDword.Bit[5].ToOnOffString(scfUpperCase)               = OFF
MyByte.ToBinString                                       = (00100010)
MyByte.ToBinString(true)                                 = (00100010)
MyByte.ToBinString(false)                                = (100010)
MyByte.ToBinString                                       = 0001_0111
MyNativeInt.ToBinString                                  = %00000000-00000000_00000011-11101000
MyQword.ToBinString                                      = OOOOOOOOOOOOOOOOOOOOXOXOXOXXXXOOXXOXXXXOXXXXXXXXXXXXXXXXXXXXXXXX
MyQword.ToBinString(false)                               = XOXOXOXXXXOOXXOXXXXOXXXXXXXXXXXXXXXXXXXXXXXX
MyQword.ToBinString(50)                                  = OOOOOOXOXOXOXXXXOOXXOXXXXOXXXXXXXXXXXXXXXXXXXXXXXX
MyQword.ToBinString(MyBinFormatSettings, false)          = %XOXO-XOXX.XXOO_-_XXOX.XXXO-XXXX.XXXX_XXXX.XXXX-XXXX.XXXX
MyQword.ToBinString(MyBinFormatSettings, 50)             = %OO_OOOO.XOXO-XOXX.XXOO_-_XXOX.XXXO-XXXX.XXXX_XXXX.XXXX-XXXX.XXXX
MyQword.ToBinString(MyBinFormatSettings, false, 50)      = %OO_OOOO.XOXO-XOXX.XXOO_-_XXOX.XXXO-XXXX.XXXX_XXXX.XXXX-XXXX.XXXX
MyQword.ToHexString                                      = 00000ABCDEFFFFFF
MyQword.ToHexString(13)                                  = 00ABCDEFFFFFF
MyQword.ToHexString(true)                                = 00000ABCDEFFFFFF
MyQword.ToHexString(false)                               = ABCDEFFFFFF
MyQword.ToHexString(DefaultHexFormatSettings)            = 00000ABCDEFFFFFF
MyQword.ToHexString(DefaultHexFormatSettings, false)     = ABCDEFFFFFF
MyQword.ToHexString(DefaultHexFormatSettings, 13)        = 00ABCDEFFFFFF
MyQword.ToHexString(DefaultHexFormatSettings, false, 13) = 00ABCDEFFFFFF
MyQword.ToHexString(MyHexFormatSettings1)                = $0000-0ABC--DEFF-FFFF
MyQword.ToHexString(MyHexFormatSettings2, true)          = [$0.0^0.0_0.A^B.C--D.E^F.F_F.F^F.F]
MyQword.ToHexString(MyHexFormatSettings2, false)         = [$A^B.C--D.E^F.F_F.F^F.F]

Compatibility with old behaviour of ToBinString and ToHexString is kept.

Please review the patch.


> Sent: Thursday, July 08, 2021 at 9:51 AM
> From: "Michael Van Canneyt" <michael at freepascal.org>
> To: "Zeljko Avramovic via fpc-devel" <fpc-devel at lists.freepascal.org>
> Cc: "Zeljko Avramovic" <avra at writeme.com>
> Subject: Re: [fpc-devel] BitHelpers
>
> 
> 
> On Thu, 8 Jul 2021, Zeljko Avramovic via fpc-devel wrote:
> 
> > BitHelpers are quite mature now and I would like to see them as part of FreePascal. If devs agree to that, then I would like to discuss what is the best way to include them. As mentioned at https://forum.lazarus.freepascal.org/index.php/topic,41672.msg409880.html#msg409880, Thaddy would like to see them available out of the box (added to syshelp*.inc), but I would prefer to see them as a separate package.
> >
> > What do you think would be the best way? I can do whatever is better, but I would like to hear your thoutghs first.
> >
> > BitHelpers info can be found at the beginning of that forum thread, at repo https://bitbucket.org/avra/bithelpers, and in the wiki https://wiki.freepascal.org/BitHelpers.
> 
> There are already bithelpers in the sysutils unit. If you want to extend
> them, that's fine. Just post a patch in the bugtracker...
> 
> Michael.


More information about the fpc-devel mailing list