Announcement

Collapse
No announcement yet.

C Bitfields

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

  • C Bitfields

    I have a a C bifield to port:
    Code:
    typedef struct BIT_FIELD_STRUCT
    {
       ULONG b1 : 4;     // bits[3:0]
       ULONG b2 : 4;
       ULONG b3 : 4;
       ULONG b4 : 4;
       ULONG b5 : 4;
       ULONG b6 : 4;
       ULONG b7 : 4;
       ULONG b8 : 4;     // bits[31:28]
    } BIT_FIELD;
    My C book tells me that C compiles bitfields into a contiguous stream of bits
    regardless of the member type declaration, so the port to PB would seem to be:
    Code:
    TYPE BIT_FIELD
       BitField    as DWORD
    END TYPE
    I presume that I port C code like:
    Code:
       ABitField.b1 = 0x09
    over to PB as:
    Code:
       ABitField.BitField = ABitField.BitField AND &HFFFFFFF0   ' Clear the lowest 4 bits
       ABitField.BitField = ABitField.BitField OR &H09          ' Set the lower 4 bits to the new value
    Look right?

    Thanks!

    ------------------
    Mark Newman

    [This message has been edited by Mark Newman (edited May 01, 2001).]
    Mark Newman

  • #2
    Looks good to me.

    ------------------
    Tom Hanlin
    PowerBASIC Staff

    Comment


    • #3
      Thanks Tom!

      ------------------
      Mark Newman
      Mark Newman

      Comment

      Working...
      X