Aug 15, 2014 06:02 AM
(This post was last modified: Aug 15, 2014 06:11 AM by sanderele1.)
So basically this allows you to have 8 booleans in one byte, instead of the normal 1 bool for one byte. It also allows you to acces the shared GetBit and Setbit methods, so you can fuck around yourselves with tiny datatypes and whatnot.
- SetBool(Index As Integer, Value As Boolean)
Set's a boolean at the specified index (0-7) to the specified value
-GetBool(Index As Integer) As Boolean
Get's the value of the boolean at the specified index (0-7)
-ToByte() As Byte
Returns a byte which contains all of the booleans
-ToBools(IByte As Byte)
Set's the booleans values to be the ones that are contained within the byte
-Shared SetBit(IByte As Byte, Offset As Byte, Value As Boolean) As Byte
Set's a bit at the specified offset to the value specified, inside of the specified Byte
-Shared GetBit(IByte As Byte, Offset As Byte) As Boolean
Returns a bit's value at the specified offset, in the specified byte
Hopefully someone finds this helpfull. It's main purpose is to be used in networking.
And please leave a constructive comment ^^
PHP Code
<?php
Public Class BitBool
Dim InternalBools(7) As Boolean
Public Sub SetBool(ByRef Index As Integer, ByRef Value As Boolean)
If Index < 0 Or Index > 7 Then
Throw New IndexOutOfRangeException("Index must be between 0 or 7")
End If
InternalBools(Index) = Value
End Sub
Public Function GetBool(ByRef Index As Integer) As Boolean
If Index < 0 Or Index > 7 Then
Throw New IndexOutOfRangeException("Index must be between 0 or 7")
End If
Return InternalBools(Index)
End Function
Public Function ToByte() As Byte
Dim IByte As Byte
IByte = SetBit(IByte, 0, InternalBools(0))
IByte = SetBit(IByte, 1, InternalBools(1))
IByte = SetBit(IByte, 2, InternalBools(2))
IByte = SetBit(IByte, 3, InternalBools(3))
IByte = SetBit(IByte, 4, InternalBools(4))
IByte = SetBit(IByte, 5, InternalBools(5))
IByte = SetBit(IByte, 6, InternalBools(6))
IByte = SetBit(IByte, 7, InternalBools(7))
Return IByte
End Function
Public Sub ToBools(ByVal IByte As Byte)
InternalBools(0) = GetBit(IByte, 0)
InternalBools(1) = GetBit(IByte, 1)
InternalBools(2) = GetBit(IByte, 2)
InternalBools(3) = GetBit(IByte, 3)
InternalBools(4) = GetBit(IByte, 4)
InternalBools(5) = GetBit(IByte, 5)
InternalBools(6) = GetBit(IByte, 6)
InternalBools(7) = GetBit(IByte, 7)
End Sub
Public Shared Function SetBit(ByVal IByte As Byte, ByVal Offset As Byte, ByVal Value As Boolean) As Byte
If Offset < 0 Or Offset > 7 Then
Throw New IndexOutOfRangeException("Offset must be between 0 and 7")
End If
If Value Then
Dim Mask As Byte
Mask = 1 << Offset
Return IByte Or Mask
Else
Dim Mask As Byte
Mask = 255 - (1 << Offset)
Return IByte And Mask
End If
End Function
Public Shared Function GetBit(ByVal IByte As Byte, ByVal Offset As Byte) As Boolean
If Offset < 0 Or Offset > 7 Then
Throw New IndexOutOfRangeException("Offset must be between 0 and 7")
End If
Dim Mask As Byte
Mask = 1 << Offset
Return (IByte And Mask) <> 0
End Function
End Class
- SetBool(Index As Integer, Value As Boolean)
Set's a boolean at the specified index (0-7) to the specified value
-GetBool(Index As Integer) As Boolean
Get's the value of the boolean at the specified index (0-7)
-ToByte() As Byte
Returns a byte which contains all of the booleans
-ToBools(IByte As Byte)
Set's the booleans values to be the ones that are contained within the byte
-Shared SetBit(IByte As Byte, Offset As Byte, Value As Boolean) As Byte
Set's a bit at the specified offset to the value specified, inside of the specified Byte
-Shared GetBit(IByte As Byte, Offset As Byte) As Boolean
Returns a bit's value at the specified offset, in the specified byte
Hopefully someone finds this helpfull. It's main purpose is to be used in networking.
And please leave a constructive comment ^^


![[Image: WMwSRhx.gif]](https://i.imgur.com/WMwSRhx.gif)

![[Image: IQE6i8G.png]](https://i.imgur.com/IQE6i8G.png)
