BITS function   

Purpose

Converts an integer class value into another data type, based upon the bit pattern of the value.  This is particularly helpful in converting between signed and unsignned 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 integer 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.

Restrictions

The superseded syntax will continue to be supported for a limited period of time, although existing code should be converted to the new syntax as soon as possible.

Superseded syntax

Replacement syntax

ByteVar  = BITS?(expr)

ByteVar  = BITS(BYTE, expr)

WordVar  = BITS??(expr)

WordVar  = BITS(WORD, expr)

DWordVar = BITS???(expr)

DWordVar = BITS(DWORD, expr)

IntVar   = BITS%(expr)

IntVar   = BITS(INT, expr)

Longvar  = BITS&(expr)

Longvar  = BITS(LONG, expr)

See also

BIT CALC statementBIT functionBIT statementBITS functions, BITSE