How to Create and Use C Structure Bit Fields in ATEasy

Knowledge Base Article # Q200015

Read Prior Article Read Next Article
Summary Describes how to create a bit field in ATEasy 3
Solution:

Bit fields are not part of the ATEasy language. To create a bit field-like structure, you can define a member as an integer and manipilate the field using the Or or And operators to set values in the fields. To clear a field you can use the Not operator.

For example if the C structure was :

Struct Fields  {       ...       DWORD a : 5;       DWORD b: 3;       ...  }


Define the Bit field as dw in ATEasy:

struct Fields  {        ...        dwFields : Dword        ...  }
  

Define some constants:

A _MASK: Dword=0x1F         A _POS: Dword=0         B_MASK : Dword=0x7         B_POS: Dword=5


To clear b use:

f.dwFiellds =f.dwFiellds & not (B_MASK shl B_POS)


To set b use:

f.dwFiellds =f.dwFiellds & not (B_MASK shl B_POS) or (bNew shl B_POS)

Article Date 2/12/2001
Keywords ATEasy, C Structure, bit fields

0 ratings | 0 out of 5
Read Prior Article Read Next Article