Purpose |
Converts an integral value into another data type, based upon the bit pattern of the value. This is particularly helpful in converting between signed and unsigned representations. |
Syntax |
resultvar = BITS(datatype, expression) |
datatype |
The parameter datatype may be BYTE, WORD, DWORD, INTEGER, or LONG to specify the new data type which should be returned by the function. |
expression |
An integral class variable, expression, or numeric literal, which designates the original value to be converted. |
Remarks |
Since the integer value -1 and word value 65535 have the identical bit pattern of 1111111111111111, BITS(WORD,-1) would return the unsigned word value of 65535. Of course, BITS(INTEGER,65535) would then return the integer value -1. Other values and data types would follow the same pattern and rules. This newer form of BITS condenses the functionality of the older forms (BITS%, BITS&, BITS?, BITS?? and BITS???) into a single function. In particular, this provides for the addition of new data types in future version of PowerBASIC, particularly those which may not have an associated type-specifier character. |
See also |
BIT CALC statement, BIT function, BIT statement, BITS$, BITSE |