BitCombine - Make a 16 bit value from two 8 bit values or a 32 bit value from two 16 bit values

Top  Previous  Next

Syntax

<nReturnValue> := BitCombine( <nLoValue>, <nHiValue>, <nBytesPerValue>, <lNoSignFlag> )

Parameters

<nLoValue>

 

The low order component (8 or 16 bits) to be combined into a 16 or 32 bit value. 8 bit values can be in the range of -128 to + 127 (signed) or in the range of 0 to 255 (unsigned). 16 bit values can be in the range of -32768 to 32767 (signed) or in the range of 0 to 65535 (unsigned).

 

<nHiValue>

 

The high order component (8 or 16 bits) to be combined into a 16 or 32 bit value.  8 bit values can be in the range of -128 to + 127 (signed) or in the range of 0 to 255 (unsigned). 16 bit values can be in the range of -32768 to 32767 (signed) or in the range of 0 to 65535 (unsigned).

 

<nBytesPerValue>

 

Size of <nLoValue> and <nHiValue> in bytes. A value of 1 combines two BYTEs to a WORD and a value of 2 combines two WORD values to a DWORD value.

 

<lNoSignFlag>

 

Flag to indicate if the return value should be signed or not. This parameter directs if bit 15 (word) or bit 31 (DWORD) should not be interpreted as a sign bit.

Return value

Depending on <nBytesPerValue> the two values <nLoValue> and <nHiValue> are combined to a 16 bit or 32 bit integer. The resulting value will be interpreted as a signed (<lNoSignFlag>=.F.) or an unsigned number (<lNoSignFlag>=.T.).

Description

BitCombine combines the bit patterns of two integer numbers (8 or 16 bits wide) to a new pattern twice their size. This pattern is interpreted as a signed or unsigned number. This function is used for the data-combination macros found in windef.ch.

Classification

Core

Category

Bit manipulation

Quick Info

Library: cckptcor.lib / cckptcor.dll

Example

 

#INCLUDE "CockpitCoreLibs.ch"

 

FUNCTION Main

 

* This will output the value 257 (0000 0001 0000 0001, unsigned)

? BitCombine(1,1,1,.T.)

 

* This will output the value -1 (1111 1111 1111 1111, signed)

? BitCombine(255,255,1,.F.)

 

RETURN NIL