HomeClarion Live! UniversityBAND and a GetBit Function by Larry Sand and Mark Goldberg
 
  • PDF

BAND and a GetBit Function by Larry Sand and Mark Goldberg

Larry Sand:

MG: This is what i do to allow the use of the Clarion FONT: equates in api calls:

Self.FontsQ.lf.lfWeight  = Band(fontStyle, FONT:weight)
Self.FontsQ.lf.lfItalic  = Choose(Band(fontStyle, FONT:italic) > 0, True, False)
Self.FontsQ.lf.lfUnderline = Choose(Band(fontStyle, FONT:underline) > 0, True, False)
Self.FontsQ.lf.lfStrikeOut = Choose(Band(fontStyle, FONT:strikeout) > 0, True, False)

lf is a LOGFONT structure

Mark.Goldberg:

FWIW, I wrote   .GetBit methods a long time ago
I find that clearer than CHOOSE(BAND( Value, Mask) > 0)

I find it interesting that 7FFH is the mask for Weight
given that it only goes to 1000
: 7FFH = 2047 (decimal)

Larry Sand:

so does GetBit() mean IsBitSet() or does it mean return value that BAND() does, the first i think.
 3FFH would look silly and the next style bits values would be confusing also. now the split is with the 4th hex character

Mark.Goldberg:

GetBit just means IsBitSet (and was written for a BYTE)
.GetBits supports a Lo/Hi bit range in the flag (and was written for a LONG)
Curiously changes in BSHIFT caused that code to fail in Clarion#

ctBits.GetBit          PROCEDURE( BYTE argByte, BYTE ArgBit) !,Byte
! --------------------------------------------------------------------
! purpose: To RETURN value of requested bit: 1 or 0
!          Bit # = 0..7  (Bit: 0 => +1, Bit: 7=> +128)
! updated: 7/28/97 (2.5ß1) RETURN 0 or 1 vs 2^argBit used to
!          RETURN(BAND(ArgByte,BShift(1,ArgBit)))
! --------------------------------------------------------------------

  CODE
    IF ~(ArgBit >= 0 AND ArgBit <= 7)     THEN  STOP('GetBit: Invalid ArgBit [' & ArgBit & ']')
    ELSIF BAND(ArgByte, BSHIFT(1,ArgBit)) THEN  RETURN(1)
    ELSE                                        RETURN(0)
    END

I'd write it a bit differently today
but as you can see, it was last updated over 13 years ago

Mark.Goldberg: Hmmm, I have mask based methods for .SetBitMask and .ClearBitMask
but not for .GetBitMask

Also FWIW:

<<< Self.FontsQ.lf.lfUnderline = Choose(Band(fontStyle, FONT:underline) > 0, True, False)

can be written:

Self.FontsQ.lf.lfUnderline = Choose(Band(fontStyle, FONT:underline) > 0 )
Joomla Templates: from JoomlaShack