Announcement

Collapse
No announcement yet.

Bits Function

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • Bits Function

    Please add your comments and suggestions as a Reply to this thread.





    PB/WIN - BITS function

    Purpose
    Converts an integral value into another data type, based upon the bit pattern of the value. This is particularly helpful in converting between signed and unsigned representations.
    Syntax
    resultvar datatype, expression)
    datatype
    The parameter datatype may be BYTE, WORD, DWORD, INTEGER, or LONG to specify the new data type which should be returned by the function.

    expression
    An integral class variable, expression, or numeric literal, which designates the original value to be converted.
    Remarks
    Since the integer value -1 and word value 65535 have the identical bit pattern of 1111111111111111, BITS(WORD,-1) would return the unsigned word value of 65535. Of course, BITS(INTEGER,65535) would then return the integer value -1. Other values and data types would follow the same pattern and rules.

    This newer form of BITS condenses the functionality of the older forms (BITS%, BITS&, BITS?, BITS?? and BITS???) into a single function. In particular, this provides for the addition of new data types in future version of PowerBASIC, particularly those which may not have an associated type-specifier character.
    See Also
    Last edited by Gary Beene; 28 Oct 2014, 06:46 PM.

  • #2
    BITS function syntax is:
    resultvar = BITS(datatype, expression)

    -

    Superseded BITS function from PB/Win 9.x, PB/CC 5.x.
    Still supported, read restrictions section below.

    Purpose
    Converts an integer class value into another data type, based upon the bit pattern of the value. This is particularly helpful in converting between signed and unsigned representations.

    Syntax
    resultvar = BITS(datatype, expression)

    datatype
    The parameter datatype may be BYTE, WORD, DWORD, INTEGER, or LONG to specify the new data type which should be returned by the function.

    expression
    An integer class variable, expression, or numeric literal, which designates the original value to be converted.

    Remarks
    Since the integer value -1 and word value 65535 have the identical bit pattern of 1111111111111111, BITS(WORD,-1) would return the unsigned word value of 65535. Of course, BITS(INTEGER,65535) would then return the integer value -1. Other values and data types would follow the same pattern and rules.

    This newer form of BITS condenses the functionality of the older forms (BITS%, BITS&, BITS?, BITS?? and BITS???) into a single function. In particular, this provides for the addition of new data types in future version of Classic PowerBASIC, particularly those which may not have an associated type-specifier character.

    Restrictions
    The superseded syntax will continue to be supported for a limited period of time, although existing code should be converted to the new syntax as soon as possible.

    Code:
    Superseded syntax          Replacement syntax
    
    ByteVar  = BITS?(expr)     ByteVar  = BITS(BYTE, expr)
    WordVar  = BITS??(expr)    WordVar  = BITS(WORD, expr)
    DWordVar = BITS???(expr)   DWordVar = BITS(DWORD, expr)
    IntVar   = BITS%(expr)     IntVar   = BITS(INT, expr)
    Longvar  = BITS&(expr)     Longvar  = BITS(LONG, expr)
    See also
    BIT CALC statement, BIT function, BIT statement, BITS functions, BITSE

    Comment


    • #3
      Code:
      function    Accepts    Returns
      
      BITS?    Long-integer    Byte (least-significant 8 bits, unsigned)
      BITS??   Long-integer    Word (least-significant 16 bits, unsigned)
      BITS???  Quad-integer    Double-word (least-significant 32 bits, unsigned)
      BITS%    Long-integer    Integer (least-significant 16 bits, signed)
      BITS&    Quad-integer    Long-integer (least-significant 32 bits, signed)

      Comment


      • #4
        The demise of the type delimited BITS functions has long ben predicted. Version 8 ManuaL

        "The BITS syntax provides for the addition of new data types in future versions ofPowerBASIC, which may not support type-specifier characters. Existing code should be converted to the new syntax as soon as possible"

        Comment


        • #5
          Old BITS references found in J. Roca includes version WINAPI_III_107 WinUser.inc:
          Code:
          'old MACRO GET_APPCOMMAND_LPARAM(lParam) = BITS%(HI(WORD, lParam) AND (NOT %FAPPCOMMAND_MASK))
          'old MACRO GET_DEVICE_LPARAM(lParam)     = BITS??(HI(WORD, lParam) AND %FAPPCOMMAND_MASK)
          
          'Conversion to new version of BITS
          'old MACRO GET_APPCOMMAND_LPARAM(lParam) = BITS(INTEGER, HI(WORD, lParam) AND (NOT %FAPPCOMMAND_MASK))
          'old MACRO GET_DEVICE_LPARAM(lParam)     = BITS(WORD, HI(WORD, lParam) AND %FAPPCOMMAND_MASK)
          
          'Replacement MACROS
          MACRO GET_APPCOMMAND_LPARAM(lParam)  = HI(WORD, lParam) AND &h0FFF
          MACRO GET_DEVICE_LPARAM(lParam)      = HI(WORD, lParam) AND &hF000
          MACRO GET_MOUSEORKEY_LPARAM          = GET_DEVICE_LPARAM
          MACRO GET_FLAGS_LPARAM(lParam)       = LO(WORD, lParam)
          MACRO GET_KEYSTATE_LPARAM(lParam)    = GET_FLAGS_LPARAM(lParam)

          Comment

          Working...
          X