Project

General

Profile

Statistics
| Revision:

vdfsplat / AppSrc / cWinFunc.pkg @ 56

History | View | Annotate | Download (3.18 KB)

1 19 wil
//***************************************************************************
2
// binary.pkg
3
//
4
// Copyright (c) 1999-2001 Out of the Box Consulting, Inc.
5
// All rights reserved.
6
//
7
//***************************************************************************
8
//  Description:
9
//      This is a collection of functions/procedures to aid in binary
10
//      operations.
11
//
12
//  Author: Oliver T. Nelson, Sture Anderson
13
//***************************************************************************
14
15
Function lshift global Integer iVal Integer iPositions Returns Integer
16
    Integer i
17
    BigInt bVal
18
    For i From 1 To iPositions
19
        Move (iVal * 2) To bVal
20
        If (bVal >= 2147483648) Move (bVal - 2147483648) To iVal
21
        Else Move bVal To iVal
22
    Loop
23
    Function_Return iVal
24
End_Function
25
26
Function rshift global Integer iVal Integer iPositions Returns Integer
27
    Function_Return (iVal / (2^iPositions))
28
End_Function
29
30
Function rshiftabs global Integer iVal Integer iPositions Returns Integer
31
    Number iHighOrder
32
    UInteger iCnt
33
    Number nVal
34
35
    If (iVal < 0) Begin
36
        Move (Number(iVal) + Number(4294967296)) To nVal
37
        Move (nVal / (2^iPositions)) To iVal
38
    End
39
    Else Move (iVal / (2^iPositions)) To iVal
40
    Function_Return iVal
41
End_Function
42
43
Function rol global Integer iVal Integer iCnt Returns Integer
44
    Function_Return (lshift(iVal, iCnt) Ior rshiftabs(iVal, (32 - iCnt)))
45
End_Function
46
47
Function inot global Integer iValue Returns Integer
48
    Function_Return ( (iValue * -1) - 1)
49
End_Function
50
51
Function xor global Integer i1 Integer i2 Returns Integer
52
    Function_Return ( (i1 Ior i2) - (i1 Iand i2) )
53
End_Function
54
55
#IFNDEF GET_BYTETOHEX
56
// **WvA: 27-07-2004 Check added is already declared in VDFQuery strings.nui
57
Function ByteToHex global Integer byte# Returns String
58
  Function_Return (Mid("0123456789ABCDEF",1,byte#/16+1)+Mid("0123456789ABCDEF",1,(byte# Iand 15)+1))
59
End_Function
60
#ENDIF
61
62
Function WordToByte Global Integer wI  Returns String
63
    Function_Return (Character(wI Iand 255)+Character(wI/256))
64
End_Function
65
66
Function WordToHex Global Integer wI  Returns String
67
    Function_Return (ByteToHex(Character(wI Iand 255))+ByteToHex(Character(wI/256)))
68
End_Function
69
70
Function DwordToHex Global Integer aDWord Returns String
71
    Function_Return ( ByteToHex(hi(aDWORD)/256)  +  ByteToHex(hi(aDWORD) Iand 255)  +  ByteToHex(low(aDWORD)/256)  +  ByteToHex(low(aDWORD) Iand 255)  )
72
End_Function
73
74
// **WvA: 27-07-2004 added
75
Function IntToHex Global Integer iValue Returns String
76
    Function_Return (DwordToHex(iValue))
77
End_Function // IntToHex
78
79
Function Ptr2Str Pointer lpsDataPointer Returns String
80
    String sResult sCharacter
81
    Integer iVoid
82
    Pointer pCharacter
83
    If (lpsDataPointer <> 0) Begin
84
        ZeroString 1 To sCharacter
85
        GetAddress Of sCharacter To pCharacter
86
        Move (CopyMemory (pCharacter, lpsDataPointer, 1)) To iVoid
87
        While (Ascii (sCharacter) <> 0)
88
            Move (sResult + sCharacter) To sResult
89
            Increment lpsDataPointer
90
            Move (CopyMemory (pCharacter, lpsDataPointer, 1)) To iVoid
91
        End
92
    End
93
    Function_Return sResult
94
End_Function