Announcement

Collapse
No announcement yet.

Implied bit array - what is it?

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

  • Implied bit array - what is it?

    From the online help file:

    The BIT function is used to determine the value of one particular bit in an integer variable or implied bit array.
    BIT {SET|RESET|TOGGLE} intVar, bitNumber

    integer var must be one of the integer types: byte, word, (short) integer, double word, long integer, or quad integer. The allowable range for the parameter bitNumber is the same as that of a long integer (making it possible to have implicit bit arrays of more than 2 billion bits in size. Bits 0 to 15 are in the first word starting at intVar, bits 16-31 are in the next word, etc.). The first bit position is always zero.
    I cannot seem to find any other mention of implied bit arrays - how to define them etc. Is it simply a single dimensional array of integer type? I need to keep track of 84 bit values, so it seems like a handy feature...

    Thanks,
    Ketil


    [This message has been edited by Ketil Krumm (edited February 01, 2000).]

  • #2
    An implicit bit array is really an explicit integer-class array, but treated as an array it bits.

    In other words, an array of 10 long integers yields an implicit bit array of 320 bits (32 bits * 10 subscripts = 320 bits), whose bit subscript range extends from 0 through to 319.

    To get an bit array of 84 bits, a LONG integer array with 3 subscripts will be suitable, ie: DIM A&(0:2)

    -------------
    Lance
    PowerBASIC Support
    mailto:[email protected][email protected]</A>
    Lance
    mailto:[email protected]

    Comment


    • #3
      Lance,

      Thanks for confirming my assumptions. A couple of additional questions, though related to the following pick'n'mix from the help file on the BIT function & statement:

      Code:
      x% = 7
      z% = BIT(x%, 33)
      BIT SET x%, 37
      This is what had me confused in the first place: Since x% is a 16-bit integer there is no bit 33 and 37... Is this an error in the help file or have I missed something obvious?

      Assuming I use Dim A&(0:2) for my 84-bit array as you suggested, which of the following would then be the correct reference for use with the BIT function/statement:

      Code:
      BIT(A&(0), bitNumber)
      BIT(A&, bitNumber)
      Does the lower bound of an implicit bit array have to be 0? The app I'm working on reads serial data from a port, and everything else in the app is channel-based. Dim'ing bit arrays like

      Code:
      Dim afFull(1 to 6) As Long
      Dim afSub(7 to 22) as Long
      would be helpful to the overall logic of the procedures.

      Finally, can I 'fake' the starting point of the array to manipulate bits from a given channel as in the following example:

      Code:
      Dim afFull(1 to 6) As Long
      Bit Set afFull(2), 3
      Would this set the third bit of channel 2, i.e. bit 34 of the array?

      Thanks,
      Ketil


      ------------------

      Comment


      • #4
        Ketil --

        > Since x% is a 16-bit integer there is no bit 33 and 37...

        True, but the remarks that are included after those lines in the Help File say this:

        Code:
        z% = BIT(x%, 33)  ' bit 2 of 2nd word starting at x%
        BIT SET x%, 37    ' Sets bit 6 of 3rd word starting at x to 1
        The first line sets bit 2 of the second word starting at the location of x%... which is, as you pointed out, not part of x%. That's perfectly legal, assuming that you know what is in memory at that location.

        > which of the following would then be the correct reference
        >
        > BIT(A&(0), bitNumber)
        > BIT(A&, bitNumber)

        The first one.

        > Does the lower bound of an implicit bit array have to be 0

        No.

        > Finally, can I 'fake' the starting point of the array...

        Yes.

        -- Eric


        ------------------
        Perfect Sync: Perfect Sync Development Tools
        Email: mailto:[email protected][email protected]</A>



        [This message has been edited by Eric Pearson (edited February 07, 2000).]
        "Not my circus, not my monkeys."

        Comment

        Working...
        X