BitShiftMaskSign - Shift, mask and sign a 32 bit value

Top  Previous  Next

Syntax

<nReturnValue> := BitShiftMaskSign( <nValLong>, <nByteShiftRightCount>, <nValidByteCount>, <lUnsigned> )

Parameters

<nValLong>

 

The LONG value to be manipulated

 

<nByteShiftRightCount>

 

The number of bytes the value is to be shifted right. Valid values: 0, 1, 2, 3.

 

<nValidByteCount>

 

The number of valid bytes (from the right). This is the masking part of the compound operation. Valid values: 0, 1, 2, 4.

 

<lUnsigned>

 

Flag if the resulting number should be interpreted as unsigned.

Return value

The resulting value after the shifting, masking and sign-interpreting.

Description

BitShiftMaskSign is a compound operation used for data extraction from LONG values. It implements a byte wise shift right which allows to move the data you're interested in to the right in the 32bit value. After that you can cut off insignificant data on the left by specifying a number of valid bytes on the right. The result of these operations can be interpreted as a signed or an unsigned value. This function is used for the data-extraction macros found in windef.ch.

Classification

Core

Category

Bit manipulation

Quick Info

Library: cckptcor.lib / cckptcor.dll

See also

BitCombine, BitShiftMaskSign

Example

 

#INCLUDE "CockpitCoreLibs.ch"

 

FUNCTION Main

 

* This should display 44444

? HighUnsignedIntOfUnsignedLong(44444*65536)

 

RETURN NIL

 

* return the high order unsigned integer (16 bits, no sign)

FUNCTION HighUnsignedIntOfUnsignedLong(p_long)

 

RETURN BitShiftMaskSign(ULong2Long(p_long),2,2,.T.)