SPL to HP C/XL Migration Guide (30231-90001)
5-9
Figure 5-2. HP C/XL BEXTRACT Macro Directive: Bit Extraction
_____________________________________________________________
| |
| unsigned short int BEXTRACT( SOURCE , SBIT , LEN ) |
| unsigned short int SOURCE , SBIT , LEN ; |
| { |
| return ( (unsigned short int) |
| ( ( SOURCE << SBIT ) >> ( 16 - LEN ) ) ) ;|
| } |
_____________________________________________________________
Figure 5-3. HP C/XL BEXTRACT Function: Bit Extraction
Either the macro or the function may be executed with the same format as
the SPL function, e.g., "BEXTRACT(Y,10,4)", so further conversion is
unnecessary.
Bit Fields.
It is common practice in SPL to pack fields of bits into a single 16-bit
word, and refer to them with DEFINE declarations, such as:
__________________________________________________
| |
| LOGICAL WORD, A, B, C; |
| |
| DEFINE FIELD'A = (0:10)#, |
| FIELD'B = (10:4)#, |
| FIELD'C = (14:2)#; |
| ... |
| WORD := %(16)F30C; <<set all fields>> |
| A := WORD.FIELD'A; <<bits 0 through 9>> |
| B := WORD.FIELD'B; <<bits 10 through 13>>|
| C := WORD.FIELD'C; <<bits 14 through 15>>|
__________________________________________________
A similar operation may be performed in HP C/XL with union and struct
declarations:
_________________________________________
| |
| unsigned short A, B, C; |
| |
| union { |
| struct { |
| FIELD_A : 10; |
| FIELD_B : 4; |
| FIELD_C : 2; |
| } BITS; |
| unsigned short ALL16; |
| } WORD; |
| ... |
| WORD.ALL16 = 0xF30C; /*set all fields*/* |
| A = WORD.BITS.FIELD_A; /*bits 0 through 9*/ |
| B = WORD.BITS.FIELD_B; /*bits 10 through 13*/|
| C = WORD.BITS.FIELD_C; /*bits 14 through 15*/|
_____________________________________________________