SPL to HP C/XL Migration Guide (30231-90001)

5- 8
Bit Extraction
Table 5-12. Bit Extraction
---------------------------------------------------------------------------------------------
| | |
| SPL | HP C/XL Equivalent |
| | |
---------------------------------------------------------------------------------------------
| | |
|
bit-extraction-operation
: | No direct equivalent. |
| | |
|
source
. (
sbit
:
len
) | |
| | |
|
source
: | |
| is a 16-bit value. | |
| | |
|
sbit
,
len
: | |
| are values from 0 to 15. | |
| | |
---------------------------------------------------------------------------------------------
Step 1: Convert the SPL operation to a function procedure, such as
BEXTRACT shown in Figure 5-1.
__________________________________________________________________
| |
| LOGICAL PROCEDURE BEXTRACT ( SOURCE , SBIT , LEN ) ; |
| VALUE SOURCE , SBIT , LEN ; |
| LOGICAL SOURCE ; |
| INTEGER SBIT , LEN ; |
| BEGIN |
| BEXTRACT := ( SOURCE & LSL( SBIT ) ) & LSR( 16 - LEN ) ;|
| END ; |
__________________________________________________________________
Figure 5-1. SPL BEXTRACT Procedure: Bit Extraction
In the procedure, the formal parameter names correspond to the variables
in the syntax above. SOURCE is the word from which to extract bits, SBIT
is the starting bit, and LEN is the number of bits.
To use it, replace an expression like
Y.(10:4);
with
BEXTRACT(Y,10,4);
Step 2: Replace the SPL function with the #define macro directive in
Figure 5-2 or the HP C/XL function in Figure 5-3.
__________________________________________________________
| |
| #define BEXTRACT( SOURCE , SBIT , LEN ) \ |
| ( (unsigned short int) \ |
| ( ( (SOURCE) << (SBIT) ) ) >> ( 16 - (LEN) ) )|
__________________________________________________________