//*************************************************************************** // binary.pkg // // Copyright (c) 1999-2001 Out of the Box Consulting, Inc. // All rights reserved. // //*************************************************************************** // Description: // This is a collection of functions/procedures to aid in binary // operations. // // Author: Oliver T. Nelson, Sture Anderson //*************************************************************************** Function lshift global Integer iVal Integer iPositions Returns Integer Integer i BigInt bVal For i From 1 To iPositions Move (iVal * 2) To bVal If (bVal >= 2147483648) Move (bVal - 2147483648) To iVal Else Move bVal To iVal Loop Function_Return iVal End_Function Function rshift global Integer iVal Integer iPositions Returns Integer Function_Return (iVal / (2^iPositions)) End_Function Function rshiftabs global Integer iVal Integer iPositions Returns Integer Number iHighOrder UInteger iCnt Number nVal If (iVal < 0) Begin Move (Number(iVal) + Number(4294967296)) To nVal Move (nVal / (2^iPositions)) To iVal End Else Move (iVal / (2^iPositions)) To iVal Function_Return iVal End_Function Function rol global Integer iVal Integer iCnt Returns Integer Function_Return (lshift(iVal, iCnt) Ior rshiftabs(iVal, (32 - iCnt))) End_Function Function inot global Integer iValue Returns Integer Function_Return ( (iValue * -1) - 1) End_Function Function xor global Integer i1 Integer i2 Returns Integer Function_Return ( (i1 Ior i2) - (i1 Iand i2) ) End_Function #IFNDEF GET_BYTETOHEX // **WvA: 27-07-2004 Check added is already declared in VDFQuery strings.nui Function ByteToHex global Integer byte# Returns String Function_Return (Mid("0123456789ABCDEF",1,byte#/16+1)+Mid("0123456789ABCDEF",1,(byte# Iand 15)+1)) End_Function #ENDIF Function WordToByte Global Integer wI Returns String Function_Return (Character(wI Iand 255)+Character(wI/256)) End_Function Function WordToHex Global Integer wI Returns String Function_Return (ByteToHex(Character(wI Iand 255))+ByteToHex(Character(wI/256))) End_Function Function DwordToHex Global Integer aDWord Returns String Function_Return ( ByteToHex(hi(aDWORD)/256) + ByteToHex(hi(aDWORD) Iand 255) + ByteToHex(low(aDWORD)/256) + ByteToHex(low(aDWORD) Iand 255) ) End_Function // **WvA: 27-07-2004 added Function IntToHex Global Integer iValue Returns String Function_Return (DwordToHex(iValue)) End_Function // IntToHex Function Ptr2Str Pointer lpsDataPointer Returns String String sResult sCharacter Integer iVoid Pointer pCharacter If (lpsDataPointer <> 0) Begin ZeroString 1 To sCharacter GetAddress Of sCharacter To pCharacter Move (CopyMemory (pCharacter, lpsDataPointer, 1)) To iVoid While (Ascii (sCharacter) <> 0) Move (sResult + sCharacter) To sResult Increment lpsDataPointer Move (CopyMemory (pCharacter, lpsDataPointer, 1)) To iVoid End End Function_Return sResult End_Function