*Bitwise*


Back to the start
Back to the libraries overview



Overview (Bitwise)
AND (Bitwise)
BytesToString (Bitwise)
Complement (Bitwise)
DecToHex (Bitwise)
HexToDec (Bitwise)
OR (Bitwise)
ShiftLeft (Bitwise)
ShiftRight (Bitwise)
StringToBytes (Bitwise)
XOR (Bitwise)


Overview (Bitwise) Top

The Bitwise library adds the bitwise operations: AND, OR, XOR and Complement (NOT).
Also included in the Bitwise library are:
? BytesToString - Returns a string from an array of bytes.
? DecToHex - Converts a decimal number to a hexadecimal number.
? HexToDec - Converts a hexadecimal number to a decimal number.
? StringToBytes - Returns an array of bytes from a string.


Before using these features you need to add a reference to Bitwise.dll, add a Bitwise object and initialize it using New1.
Example:
'First add a Bitwise object named bit.
Sub Globals

End Sub

Sub App_Start
bit.New1
msgbox(bit.XOR (123,32))
a = bit.AND(255,15)
if bit.OR(a,25) = 31 then msgbox("a = " & a)
End Sub


AND (Bitwise) Top

Computes the bitwise AND operation between two integers.
Syntax: AND (a As Int32, b As Int32) As Int32


BytesToString (Bitwise) Top

Returns a string from an array of bytes.
Syntax: BytesToString (buffer As Byte[], index As Int32, count As Int32) As String


BytesToString converts each byte in the array to a character based on its ASCII value.
buffer - An array of bytes.
index - The index of the first byte which will be converted.
count - Number of bytes to convert.
Note: buffer will stay unchanged.
Example:
'First add a Bitwise object named bit.
Sub Globals
Dim buffer(5) as Byte
End Sub

Sub App_Start
bit.New1
buffer(0) = 65
buffer(1) = 66
buffer(2) = 67
buffer(3) = 68
buffer(4) = 69
msgbox(bit.BytesToString(buffer(), 0, 5)) 'Will display "ABCDE"
End Sub


Complement (Bitwise) Top

Computes the bitwise complement (NOT) operation on an integer.
Syntax: Complement (a As Int32) As Int32


DecToHex (Bitwise) Top

Returns a hexadecimal number from a decimal number.
Syntax: DecToHex (DecimalNumber As Int32) As String
Example:
'First add a Bitwise object named bit.
Sub Globals
End Sub

Sub App_Start
bit.New1
d = 255
msgbox(bit.DecToHex(d)) 'Will display "ff"
End Sub


HexToDec (Bitwise) Top

Returns a decimal number from a hexadecimal number.
Syntax: HexToDec (HexNumber As String) As Int32
Example:
'First add a Bitwise object named bit.
Sub Globals
End Sub

Sub App_Start
bit.New1
h = "ff"
msgbox(bit.HexToDec(h)) 'Will display 255
End Sub

OR (Bitwise) Top

Computes the bitwise OR operation between two integers.
Syntax: OR(a As Int32, b As Int32) As Int32


ShiftLeft (Bitwise) Top

Shifts left the number of bits specified in the Count argument.
Syntax: ShiftLeft (number As Int32, count As Int32) As Int32
Example
num = bit.ShiftLeft (num,1) 'Same as multiplying by 2


ShiftRight (Bitwise) Top

Shifts right the number of bits specified in the Count argument.
Syntax: ShiftRight (number As Int32, count As Int32) As Int32


StringToBytes (Bitwise) Top

Returns an array of bytes from the ASCII values of the characters in the string.
Syntax: StringToBytes (string As String, index As Int32, count As Int32) As Byte[]


string - The string of characters which will be converted.
index - The index of the first character to be converted.
count - The number of character to convert.
Example:
'First add a Bitwise object named bit.
Sub Globals
Dim buffer(0) as Byte 'Declares an empty array
End Sub

Sub App_Start
bit.New1
buffer() = bit.StringToBytes("AB CDE",0,5)
msgbox("Array length: " & ArrayLen(buffer())) 'Will display 5
msgbox(buffer(1)) 'Will display 66 (the ASCII value of 'B')
End Sub


XOR (Bitwise) Top

Computes the bitwise XOR operation between two integers.
Syntax: XOR(a As Int32, b As Int32) As Int32